학습 및 테스트에서 모델 평가하기
함수 auc_train_test 는 train 세트로 모델을 학습하고 test 세트에서 평가한 AUC를 계산해요:
auc_train, auc_test = auc_train_test(variables, target, train, test)
여기서 variables 는 모델에 사용되는 변수 이름들의 리스트예요.
이번 연습에서는 이 함수를 적용해 보고, 학습 AUC와 테스트 AUC가 유사한지 확인해 보세요.
이 연습은 강의의 일부입니다
Python으로 배우는 예측 분석 입문
연습 안내
basetable이 로드되어 있어요. 학습 세트가 데이터의 70%가 되도록 분할하고, 학습 세트와 테스트 세트의 타깃 발생률이 같도록 해 주세요.auc_train_test함수를 사용해"age"와"gender_F"를 예측 변수로 하는 모델의 학습 AUC와 테스트 AUC를 계산하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Load the partitioning module
from sklearn.model_selection import train_test_split
# Create DataFrames with variables and target
X = basetable.drop('target', 1)
y = basetable["target"]
# Carry out 70-30 partititioning with stratification
X_train, X_test, y_train, y_test = ____(X, y, test_size = ____, stratify = ____)
# Create the final train and test basetables
train = pd.concat([X_train, y_train], axis=1)
test = pd.concat([X_test, y_test], axis=1)
# Apply the auc_train_test function
auc_train, auc_test = ____([____, ____], ["target"], ____, ____)
print(round(auc_train,2))
print(round(auc_test,2))