변수 선택 순서 찾기
Forward stepwise 변수 선택 절차는 빈 변수 집합에서 시작해 예측 변수를 하나씩 추가합니다. 매 단계마다 현재 변수들과 결합했을 때 AUC가 가장 높은 예측 변수를 선택합니다.
이번 연습에서는 forward stepwise 변수 선택 절차를 직접 구현해 보겠습니다. 이를 위해 미리 구현된 next_best 함수를 사용할 수 있습니다. 사용 예시는 다음과 같습니다:
next_best(current_variables,candidate_variables,target,basetable)
여기서 current_variables는 이미 모델에 포함된 변수들의 리스트이고, candidate_variables는 다음에 추가할 수 있는 변수들의 리스트입니다.
이 연습은 강의의 일부입니다
Python으로 배우는 예측 분석 입문
연습 안내
next_best함수를 사용해 다음으로 가장 좋은 변수를 계산하고next_variable에 할당하세요.current_variables리스트를 업데이트하세요.candidate_variables리스트를 업데이트하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Find the candidate variables
candidate_variables = list(basetable.columns.values)
candidate_variables.remove("target")
# Initialize the current variables
current_variables = []
# The forward stepwise variable selection procedure
number_iterations = 5
for i in range(0, number_iterations):
next_variable = ____(____, ____, ["target"], basetable)
current_variables = current_variables + [____]
candidate_variables.remove(____)
print("Variable added in step " + str(i+1) + " is " + next_variable + ".")
print(current_variables)