career-chatbot-exp / src /analyze.py
jonghhhh's picture
Upload 5 files
1ba3aae verified
Raw
History Blame Contribute Delete
1.9 kB
# analyze.py
# ───────────────────────────────────────────────────────────────────────────
# κ΅¬κΈ€μ‹œνŠΈ(λ˜λŠ” λ‹€μš΄λ‘œλ“œν•œ CSV) β†’ 쑰건별 비ꡐ 뢄석.
# DBκ°€ μ—†μœΌλ―€λ‘œ CSV 3개λ₯Ό 직접 μ½λŠ”λ‹€. long-format이라 pivot ν•œ 번이면 끝.
# ───────────────────────────────────────────────────────────────────────────
import pandas as pd
from scipy import stats
# κ΅¬κΈ€μ‹œνŠΈμ—μ„œ 받은(ν˜Ήμ€ μ‚¬μ΄λ“œλ°”μ—μ„œ 내렀받은) CSV 3개
participants = pd.read_csv("participants.csv")
messages = pd.read_csv("messages.csv")
surveys = pd.read_csv("surveys.csv")
# 1) μ™„λ£Œμžλ§Œ
done = participants[participants["completed"] == 1]
print(f"μ™„λ£Œμž: {len(done)}λͺ…")
print(done["condition"].value_counts())
# 2) 사후 섀문을 wide format으둜 (ν•œ λ¬Έν•­=ν•œ μ—΄)
post = surveys[surveys["phase"] == "post"]
post_wide = post.pivot_table(index="participant_id", columns="question_id",
values="answer", aggfunc="first")
# 3) 쑰건과 ν•©μΉ˜κΈ°
df = done[["participant_id", "condition"]].merge(post_wide, on="participant_id")
numeric = ["usefulness", "warmth", "competence", "trust", "clarity", "recommend"]
for c in numeric:
df[c] = pd.to_numeric(df[c], errors="coerce")
# 4) 쑰건별 t-test
print("\n=== 쑰건별 비ꡐ (A: λΆ„μ„κ°€ν˜•, B: λ©˜ν† ν˜•) ===")
for var in numeric:
a = df[df["condition"] == "A"][var].dropna()
b = df[df["condition"] == "B"][var].dropna()
if len(a) > 1 and len(b) > 1:
t, p = stats.ttest_ind(a, b)
print(f"{var:12s}: A={a.mean():.2f}, B={b.mean():.2f}, t={t:+.2f}, p={p:.3f}")