สำรวจผลลัพธ์ของ 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)