평가와 신뢰성¶
평가 코드는 metric을 계산하기 전에 train과 test가 실제 배포 상황을 얼마나 닮았는지 설명할 수 있어야 합니다.
먼저 확인할 누수¶
- 같은 subject의 반복 샘플이 양쪽 split에 포함되는가
- feature selection을 전체 데이터에서 수행했는가
- 수집 기관이나 cohort가 label을 대신 설명하는가
- test 결과를 보고 threshold나 preprocessing을 다시 고쳤는가
microbiome 데이터는 cohort와 실험 환경의 영향이 크기 때문에 random split만으로 일반화를 주장하기 어렵습니다. Best practices for developing microbiome-based disease diagnostic classifiers through machine learning의 검증 원칙을 이후 모델 평가에 반영합니다.
최소 보고 단위¶
| 관점 | 지표 또는 결과 |
|---|---|
| 분류 | AUROC, AUPRC, sensitivity, specificity |
| 불균형 | class prevalence, balanced accuracy, MCC |
| 확률 | Brier score, calibration curve |
| 일반화 | cohort별 결과, worst-cohort, 분산 |
| 시스템 | 학습 시간, peak memory, artifact size, inference latency |
좋은 평균 하나보다 실패한 cohort와 제한 조건을 함께 남깁니다.
검증 gate¶
새 모델은 기존 모델보다 metric 하나가 높다는 이유만으로 승격하지 않습니다. schema 호환, smoke prediction, 최소 성능, calibration과 알려진 실패 조건을 통과한 뒤 사람이 최종 승격합니다.
구현 원칙¶
scikit-learn의 Pipeline은 preprocessing과 estimator를 같은 객체로 묶어 cross-validation
각 fold의 train 부분에서만 fit되게 합니다. scaling, imputation, feature selection을
전체 데이터에 먼저 적용하지 않습니다.
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
model = make_pipeline(
StandardScaler(),
LogisticRegression(max_iter=1_000),
)
반복 샘플이나 cohort가 있으면 row random split 대신 group-aware split을 사용합니다. split manifest는 metric과 함께 저장해 다른 모델도 같은 평가 단위를 사용하게 합니다.
평가 보고서¶
- 문제, prediction 단위, label 생성 과정
- train/validation/test의 시간·subject·cohort 경계
- 단순 baseline과 model selection 기준
- 전체 metric과 confidence interval
- cohort·class·입력 품질별 오류
- calibration과 threshold 선택 근거
- 알려진 실패 조건과 사용하지 말아야 할 범위