-
Notifications
You must be signed in to change notification settings - Fork 5
비모수적 CATE 추정: 선형 모델 및 메타 러너 결과 비교 #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "33-\uBE44\uBAA8\uC218\uC801-cate-\uCD94\uC815-\uBC29\uBC95\uB860-\uAD6C\uD604"
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이번 주도 코드 작성하느라 고생 많으셨습니다!
덕분에 연속형 및 이진형 처치에 대한 비모수적 CATE 추정 및 평가(AUUC)의 전체 실무 코드 흐름을 이해할 수 있었습니다.
요약
- 학습/평가 분리: 관측(편향) 데이터로 학습하고 RCT로 평가
- 모델 구성: OLS와 S / T / X-Learner (메타 러너)를 모두 구현하여, 개별 처치 효과(CATE)의 이질성(heterogeneity) 추정 성능 비교
- 데이터셋별 목적
- Ice Cream Sales (연속형 처치)
- 목표: 가격(Price) 변화가 판매량(Sales)에 미치는 민감도 추정
- 연속 처치 변수(Price)를 중앙값 기준으로 이진화하여 “낮은 가격 vs 높은 가격” 그룹으로 AUUC 비교 수행
- Email Marketing (이진형 처치)
- 목표: 이메일 발송 여부가 전환에 미치는 영향 추정
- 이진형 처치 변수(Email 발송)를 기반으로 모델 비교
- Ice Cream Sales (연속형 처치)
- 지표/시각화: Uplift Curve + AUUC로 상위 대상 선별력을 직관적으로 비교
| "# --- 모델 1: 선형 CATE (OLS) ---\n", | ||
| "formula_linear_ice = 'sales ~ price * (temp + C(weekday) + cost)'\n", | ||
| "linear_model_ice = smf.ols(formula_linear_ice, data=train_ice).fit()\n", | ||
| "\n", | ||
| "# CATE 추정 함수 (연속형 T용)\n", | ||
| "def get_linear_cate_predictions(model, df, t_col):\n", | ||
| " df_t1 = df.copy(); df_t1[t_col] = df_t1[t_col] + 1\n", | ||
| " return model.predict(df_t1) - model.predict(df)\n", | ||
| "\n", | ||
| "test_preds_ice['cate_linear'] = get_linear_cate_predictions(linear_model_ice, test_preds_ice, T_ice_cont)\n", | ||
| "\n", | ||
| "\n", | ||
| "# --- 모델 2: S-Learner (RF) ---\n", | ||
| "rf_model_base = RandomForestRegressor(n_estimators=100, min_samples_leaf=20, random_state=42)\n", | ||
| "s_learner_ice = clone(rf_model_base)\n", | ||
| "s_learner_ice.fit(train_ice[X_ice + [T_ice_cont]], Y_train_ice)\n", | ||
| "\n", | ||
| "# CATE 추정\n", | ||
| "X_test_s_ice_t1 = X_test_ice.copy(); X_test_s_ice_t1[T_ice_cont] = test_ice[T_ice_cont] + 1\n", | ||
| "X_test_s_ice_t0 = X_test_ice.copy(); X_test_s_ice_t0[T_ice_cont] = test_ice[T_ice_cont]\n", | ||
| "test_preds_ice['cate_s_learner'] = s_learner_ice.predict(X_test_s_ice_t1) - s_learner_ice.predict(X_test_s_ice_t0)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 ols와 s-learner의 학습은 price(연속형)로 진행하고, 평가는 price_binary(이진형) AUUC로 하고있어서 불균형이 존재하는 것 같습니다.
아래와 같은 방식으로 모두 진행해보는 것도 좋을 것 같습니다.
-
전체 모델 대상 이진 비교:
OLS/S-Learner도 price_binary로 학습 및 예측하여, 모든 모델을 동일 이진 처치 기준으로 AUUC-binary 비교
-
연속 처치 기준 비교:
기존 OLS/S-Learner를 연속형 처치로 유지하고 이 두 모델만 대상으로 AUUC-continuous 비교
|
안녕하세요 리뷰어님. 주요 변경 사항은 다음과 같습니다.
걈사합니다. |
|
안녕하세요 리뷰어입니다. 우선 일정을 착각하여 리뷰가 늦은 점 사과드립니다. 다만, 커밋 기록 을 확인해보니 수정된 내용이 아직 브랜치에 반영되지 않은 것 같아, 우선은 예전 버전을 기준으로 코멘트 전달드립니다. ++ 적어주신 리뷰를 바탕으로 이진과 연속 파트 분류해주신 점 확인하였으며, 나머지 리뷰 내용만 확인해주시면 감사할 것 같습니다! |
|
안녕하세요 정현님. 이전 코멘트에서 논의했던 모든 수정 사항을 처음부터 다시 작업해서 복구 완료했습니다. 감사합니다. |
66e91c5 to
0aa5e88
Compare
0aa5e88 to
1343876
Compare
안녕하세요, 작업한 내용은 다음과 같습니다.
2개 데이터셋(아이스크림, 이메일)에 대한 CATE 모델(선형 vs 메타-러너) 비교 구현