다음으로 좋은 변수를 선택하기
Forward stepwise 변수 선택 방법은 빈 변수 집합으로 시작해서, 각 단계마다 다음으로 가장 좋은 변수를 추가해 나갑니다. 이 절차를 구현할 수 있도록 두 가지 편리한 함수를 미리 준비해 두었습니다.
auc 함수는 주어진 변수 집합 variables에 대해, 이 변수들을 예측 변수로 사용하는 모델의 AUC를 계산합니다. next_best 함수는 다음 단계에서 변수 목록에 어떤 변수를 추가해야 하는지 계산합니다.
이 연습 문제에서는 이 함수들을 직접 사용해 보며 목적을 더 잘 이해하실 수 있도록 합니다. 주어진 변수 집합의 AUC를 계산하고, 다음으로 추가할 변수가 무엇인지 계산한 뒤, 이것이 실제로 최적의 AUC로 이어지는지도 확인해 보세요.
이 연습은 강의의 일부입니다
Python으로 배우는 예측 분석 입문
연습 안내
auc함수는 미리 구현되어 있습니다."max_gift","mean_gift","min_gift"를 예측 변수로 사용하는 모델의 AUC를 계산하세요. 이 변수들은 리스트로 만들어auc함수의 첫 번째 인수로 전달해야 합니다.next_best함수는 미리 구현되어 있습니다. 현재 모델에"max_gift","mean_gift","min_gift"가 들어 있고, 후보 예측 변수가"age"와"gender_F"일 때 다음으로 추가해야 할 변수가 무엇인지 계산하세요.next_best함수의 첫 번째 인수는 현재 변수들의 리스트이고, 두 번째 인수는 후보 예측 변수들의 리스트입니다."max_gift","mean_gift","min_gift","age"를 예측 변수로 사용하는 모델의 AUC를 계산하세요."max_gift","mean_gift","min_gift","gender_F"를 예측 변수로 사용하는 모델의 AUC를 계산하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Calculate the AUC of a model that uses "max_gift", "mean_gift" and "min_gift" as predictors
auc_current = ____([____, ____, ____], ["target"], basetable)
print(round(auc_current,4))
# Calculate which variable among "age" and "gender_F" should be added to the variables "max_gift", "mean_gift" and "min_gift"
next_variable = ____([____, ____, ____], [____, ____], ["target"], basetable)
print(next_variable)
# Calculate the AUC of a model that uses "max_gift", "mean_gift", "min_gift" and "age" as predictors
auc_current_age = ____([____, ____, ____, ____], ["target"], basetable)
print(round(auc_current_age,4))
# Calculate the AUC of a model that uses "max_gift", "mean_gift", "min_gift" and "gender_F" as predictors
auc_current_gender_F = ____([____], ["target"], basetable)
print(round(auc_current_gender_F,4))