분류 예측
모델 검증에서는 최종 분류 결과뿐 아니라 예측에 대한 추가 정보가 중요한 경우가 많아요. 예를 들어 경기 승자를 예측할 때, 대부분은 어느 팀이 이길지뿐 아니라 이길 "가능성"이 얼마나 되는지도 궁금해합니다.
| Probability | Prediction | Meaning |
|---|---|---|
| 0 < .50 | 0 | Team Loses |
| .50 + | 1 | Team Wins |
이 연습에서는 tic_tac_toe 데이터셋을 사용해 .predict()와 .predict_proba() 메서드를 살펴봅니다. 첫 번째 메서드는 Player One이 게임에서 이길지 예측하고, 두 번째 메서드는 Player One이 이길 확률을 제공합니다. 랜덤 포레스트 분류 모델로는 rfc를 사용하세요.
이 연습은 강의의 일부입니다
Python에서의 모델 검증
연습 안내
- 예측값 두 개의 배열을 만드세요. 하나는 분류 결과(클래스), 다른 하나는 예측 확률입니다.
- pandas Series의
.value_counts()메서드를 사용해 각 클래스에 할당된 관측치 수를 출력하세요. probability_predictions의 첫 번째 관측치를 출력하여 확률 값이 어떻게 구성되는지 확인하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Fit the rfc model.
rfc.fit(X_train, y_train)
# Create arrays of predictions
classification_predictions = rfc.____(X_test)
probability_predictions = rfc.____(X_test)
# Print out count of binary predictions
print(pd.Series(____).____())
# Print the first value from probability_predictions
print('The first predicted probabilities are: {}'.format(____[____]))