시작하기무료로 시작하기

최고 결과 분석하기

결국 가장 중요한 것은 그리드 서치에서 가장 성능이 좋은 ‘사각형(square)’입니다. 다행히 Scikit Learn의 gridSearchCv 객체에는 최고의 사각형(또는 cv_results_의 행)에 대한 핵심 정보를 제공하는 여러 매개변수가 있습니다.

이번에 살펴볼 세 가지 속성은 다음과 같습니다.

  • best_score_ – 최고 성능의 사각형에서 얻은 점수(여기서는 ROC_AUC).
  • best_index_ – 최고 성능의 사각형에 대한 정보가 담긴 cv_results_의 행 인덱스.
  • best_params_ – 최고 점수를 내게 한 매개변수의 딕셔너리, 예: 'max_depth': 10

그리드 서치 객체 grid_rf_class가 제공됩니다.

또한 cv_results_로부터 만든 데이터프레임(cv_results_df)이 6번째 줄에서 생성되어 있어요. 이를 사용하면 결과를 인덱싱하기가 쉬워집니다.

이 연습은 강의의 일부입니다

Python에서의 하이퍼파라미터 튜닝

강의 보기

연습 안내

  • grid_rf_class에서 최고 성능의 사각형에 대한 ROC_AUC 점수를 추출해 출력하세요.
  • cv_results_df인덱스로 조회해 최고 성능 행으로부터 변수를 하나 생성하세요.
  • 최고 성능의 사각형에 대해 grid_rf_class에서 n_estimators 매개변수를 추출해 best_n_estimators 변수로 만들고, 이를 출력하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Print out the ROC_AUC score from the best-performing square
best_score = grid_rf_class._____
print(best_score)

# Create a variable from the row related to the best-performing square
cv_results_df = pd.DataFrame(grid_rf_class.cv_results_)
best_row = cv_results_df.loc[[grid_rf_class.____]]
print(best_row)

# Get the n_estimators parameter from the best-performing square and print
best_n_estimators = grid_rf_class.____["_____"]
print(best_n_estimators)
코드 편집 및 실행