샘플 크기 제한하기
과적합을 막는 또 다른 방법은 Decision Tree에서 리프(또는 노드)를 확장하는 데 필요한 최소 관측치 수를 지정하는 것입니다.
이 연습에서는 다음을 수행합니다.
- 이 최소 한계를 100으로 설정합니다.
- 새 모델을 직원 데이터에 적합합니다.
- 학습 세트와 테스트 세트 모두에서 예측 결과를 확인합니다.
변수 features_train, target_train, features_test, target_test는 작업 공간에 이미 준비되어 있습니다.
이 연습은 강의의 일부입니다
HR Analytics: Python으로 직원 이탈 예측하기
연습 안내
DecisionTreeClassifier를 초기화하고 리프의 최소 관측치 수를 100으로 설정하세요.- 학습 데이터에 의사결정나무 모델을 적합하세요.
- 학습 세트와 테스트 세트 모두에서 예측 정확도를 확인하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Initialize the DecisionTreeClassifier while limiting the sample size in leaves to 100
model_sample_100 = DecisionTreeClassifier(____, random_state=42)
# Fit the model
____.fit(features_train,____)
# Print the accuracy of the prediction (in percentage points) for the training set
print(____.score(features_train,target_train)*100)
# Print the accuracy of the prediction (in percentage points) for the test set
print(____.____(features_test,target_test)*100)