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

นำผลลัพธ์ที่ดีที่สุดไปใช้งาน

แม้การวิเคราะห์ผลลัพธ์ของ grid search จะน่าสนใจ แต่เป้าหมายสุดท้ายของเราคือการนำโมเดลไปใช้งานจริง นั่นคือการพยากรณ์บนชุดข้อมูลทดสอบด้วยออบเจ็กต์ estimator

เข้าถึงออบเจ็กต์นี้ได้ผ่าน property best_estimator_ ของออบเจ็กต์ grid search

มาดูภายใน property best_estimator_ กัน จากนั้นทำการพยากรณ์และคำนวณคะแนนประเมินผล เราจะเริ่มต้นด้วย predict แบบปกติ (ซึ่งให้ผลเป็น class predictions) แต่สำหรับคะแนน roc-auc นั้น จำเป็นต้องใช้ predict_proba แทน predict เนื่องจาก roc-auc ต้องการคะแนนความน่าจะเป็น โดยใช้ slice [:,1] เพื่อดึงค่าความน่าจะเป็นของ positive class

ชุดข้อมูล X_test และ y_test รวมถึงออบเจ็กต์ grid_rf_class จากแบบฝึกหัดก่อนหน้าพร้อมให้ใช้งานแล้ว

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

การปรับ Hyperparameter ใน Python

ดูคอร์ส

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

  • ตรวจสอบประเภทของ property best_estimator_
  • ใช้ property best_estimator_ เพื่อพยากรณ์บนชุดข้อมูลทดสอบ
  • สร้าง confusion matrix และคะแนน ROC_AUC จากผลการพยากรณ์

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

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

# See what type of object the best_estimator_ property is
print(____(____.____))

# Create an array of predictions directly using the best_estimator_ property
predictions = grid_rf_class.____._____(X_test)

# Take a look to confirm it worked, this should be an array of 1's and 0's
print(predictions[0:5])

# Now create a confusion matrix 
print("Confusion Matrix \n", confusion_matrix(y_test, ______))

# Get the ROC-AUC score
predictions_proba = grid_rf_class.best_estimator_.predict_proba(X_test)[:,1]
print("ROC-AUC Score \n", roc_auc_score(y_test, _____))
แก้ไขและรันโค้ด