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

สำรวจผลลัพธ์ของ Grid Search

ในแบบฝึกหัดนี้ เราจะสำรวจ property cv_results_ ของออบเจกต์ GridSearchCV ที่กำหนดไว้ในวิดีโอ property นี้เป็น dictionary ที่สามารถนำเข้า pandas DataFrame ได้ และมีข้อมูลที่เป็นประโยชน์มากมายเกี่ยวกับ Grid Search ที่เพิ่งรันไป

ทบทวนประเภทคอลัมน์ต่าง ๆ ใน property นี้:

  • คอลัมน์ time_
  • คอลัมน์ param_ (หนึ่งคอลัมน์ต่อ hyperparameter หนึ่งตัว) และ คอลัมน์ params เพียงคอลัมน์เดียว (ที่รวม hyperparameter ทั้งหมดไว้)
  • คอลัมน์ train_score สำหรับแต่ละ cv fold รวมถึงคอลัมน์ mean_train_score และ std_train_score
  • คอลัมน์ test_score สำหรับแต่ละ cv fold รวมถึงคอลัมน์ mean_test_score และ std_test_score
  • คอลัมน์ rank_test_score ที่มีตัวเลขตั้งแต่ 1 ถึง n (จำนวน iteration) เพื่อจัดอันดับแถวตาม mean_test_score

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

การปรับ Hyperparameter ใน Python

ดูคอร์ส

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

  • อ่าน property cv_results_ ของออบเจกต์ GridSearchCV ชื่อ grid_rf_class ลงใน DataFrame แล้วพิมพ์ออกมาทั้งหมดเพื่อตรวจสอบ
  • ดึงข้อมูลและพิมพ์คอลัมน์ เพียงคอลัมน์เดียว ที่เก็บ dictionary ของ hyperparameter ทั้งหมดที่ใช้ในแต่ละ iteration ของ Grid Search
  • ดึงข้อมูลและพิมพ์แถวที่มี mean test score ดีที่สุด โดย index ผ่านคอลัมน์ rank_test_score

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

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

# Read the cv_results property into a dataframe & print it out
cv_results_df = pd.DataFrame(grid_rf_class.____)
print(____)

# Extract and print the column with a dictionary of hyperparameters used
column = cv_results_df.loc[:, [____]]
print(____)

# Extract and print the row that had the best mean test score
best_row = cv_results_df[cv_results_df[____] == ____ ]
print(best_row)
แก้ไขและรันโค้ด