เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

วิเคราะห์ผลลัพธ์ที่ดีที่สุด

ในท้ายที่สุด สิ่งที่เราสนใจมากที่สุดคือ 'ช่อง' ที่ให้ผลลัพธ์ดีที่สุดใน grid search โชคดีที่ออบเจกต์ gridSearchCv ของ Scikit Learn มี parameter หลายตัวที่ให้ข้อมูลสำคัญเกี่ยวกับช่องที่ดีที่สุดนั้น (หรือแถวใน cv_results_) โดยเฉพาะ

มี 3 property ที่จะได้สำรวจ ได้แก่:

  • best_score_ – คะแนน (ในที่นี้คือ ROC_AUC) จากช่องที่ให้ผลลัพธ์ดีที่สุด
  • best_index_ – index ของแถวใน cv_results_ ที่เก็บข้อมูลของช่องที่ดีที่สุด
  • best_params_ – dictionary ของ parameter ที่ให้คะแนนดีที่สุด เช่น 'max_depth': 10

ออบเจกต์ grid search ชื่อ grid_rf_class พร้อมใช้งานแล้ว

ได้สร้าง dataframe (cv_results_df) จาก cv_results_ ไว้ให้แล้วในบรรทัดที่ 6 เพื่อช่วยในการ index เข้าไปยังผลลัพธ์

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การปรับ Hyperparameter ใน Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • ดึงและแสดงผล คะแนน ROC_AUC จากช่องที่ให้ผลลัพธ์ ดีที่สุด ใน grid_rf_class
  • สร้างตัวแปรจากแถวที่ดีที่สุด โดย index เข้าไปใน cv_results_df
  • สร้างตัวแปร best_n_estimators โดยดึง parameter n_estimators จากช่องที่ดีที่สุดใน grid_rf_class แล้วแสดงผลออกมา

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# 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)
แก้ไขและรันโค้ด