Files
민헌andClaude Fable 5 dfb9ad6e66 초기 커밋 — 협상 AI 에이전트 정본: 엔진·데모 콘솔·측정 인프라·증빙
- server/: FastAPI 협상 엔진 (5라운드, Q-Table/UCB, 페르소나 계측, :53117)
- frontend/: 데모 콘솔 (React+Tailwind → nginx, /api 프록시)
- eval/·testdata/: 지표 8종 측정 하네스 + 재현 가능 테스트셋
- results/: 측정 증빙 (지표별 result+provenance, raw 원본 동결+SHA256)
  ① 86.0 · ② 76.0 · ③ 5.99% · ⑥ p95 3.61ms · ⑦ 611만/년 · ⑧ 91/100 · ⑨ 99.71 · ⑩ 97.99
- docker-compose.yml + run.sh: backend+frontend 일괄 기동

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0112XUWF4bc3gGrEt8vsYCzy
2026-08-31 13:09:52 +09:00

69 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""⑨ 품목별 협상 시나리오 분류 — 독립 실행 채점기 (표준 라이브러리만).
입력: data/predictions.csv — 헤더 y_true,y_pred (분류기 test set 예측 결과)
사용: python run.py [--input data/predictions.csv] [--target 96]
산식: macro-F1 (클래스별 F1 단순 평균) — micro-F1(=accuracy) 병기
"""
import argparse
import csv
import json
from collections import defaultdict
from pathlib import Path
HERE = Path(__file__).parent
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--input", default=str(HERE / "data" / "predictions.csv"))
ap.add_argument("--target", type=float, default=96.0)
args = ap.parse_args()
with open(args.input, encoding="utf-8-sig") as f:
rows = list(csv.DictReader(f))
y_true = [r["y_true"].strip() for r in rows]
y_pred = [r["y_pred"].strip() for r in rows]
tp, fp, fn = defaultdict(int), defaultdict(int), defaultdict(int)
with open(HERE / "detail.jsonl", "w", encoding="utf-8") as df:
for i, (t, p) in enumerate(zip(y_true, y_pred)):
if t == p:
tp[t] += 1
else:
fp[p] += 1
fn[t] += 1
df.write(json.dumps({"i": i, "y_true": t, "y_pred": p, "정답": t == p},
ensure_ascii=False) + "\n")
per_class, f1s = {}, []
for c in sorted(set(y_true) | set(y_pred)):
prec = tp[c] / (tp[c] + fp[c]) if tp[c] + fp[c] else 0.0
rec = tp[c] / (tp[c] + fn[c]) if tp[c] + fn[c] else 0.0
f1 = 2 * prec * rec / (prec + rec) if prec + rec else 0.0
per_class[c] = {"precision": round(prec, 4), "recall": round(rec, 4),
"f1": round(f1, 4), "support": y_true.count(c)}
f1s.append(f1)
macro_f1 = round(100 * sum(f1s) / len(f1s), 2) if f1s else 0.0
micro_f1 = round(100 * sum(1 for t, p in zip(y_true, y_pred) if t == p) / len(y_true), 2) \
if y_true else 0.0
out = {
"n": len(y_true),
"산식": "macro-F1 (클래스별 F1 단순 평균) — 불균형 대비 보수적 채점",
"macro_f1_pct": macro_f1,
"micro_f1_pct(accuracy)": micro_f1,
"클래스별": per_class,
"target_pct": args.target,
"verdict": "PASS" if macro_f1 >= args.target else "FAIL",
}
(HERE / "result.json").write_text(json.dumps(out, ensure_ascii=False, indent=2),
encoding="utf-8")
print(json.dumps(out, ensure_ascii=False, indent=1))
if __name__ == "__main__":
main()