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

กรณีศึกษาโรคไต III: Pipeline แบบครบวงจร

ได้เวลาประกอบ transform ทั้งหมดเข้าด้วยกันพร้อมกับ XGBClassifier เพื่อสร้าง pipeline แบบครบวงจร!

นอกจาก numeric_categorical_union ที่สร้างไว้ในแบบฝึกหัดที่แล้ว ยังต้องใช้ transform อีก 2 รายการ ได้แก่ transform Dictifier() ที่เตรียมไว้ให้แล้ว และ DictVectorizer()

หลังจากสร้าง pipeline แล้ว ให้ทำ cross-validation เพื่อประเมินประสิทธิภาพของโมเดล

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

Extreme Gradient Boosting with XGBoost

ดูคอร์ส

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

  • สร้าง pipeline โดยใช้ transform numeric_categorical_union, Dictifier(), และ DictVectorizer(sort=False) พร้อมกับ estimator xgb.XGBClassifier() ที่กำหนด max_depth=3 ตั้งชื่อ transform ว่า "featureunion", "dictifier", "vectorizer" และตั้งชื่อ estimator ว่า "clf"
  • ทำ cross-validation แบบ 3-fold บน pipeline โดยใช้ cross_val_score() ส่ง pipeline (pipeline), features (kidney_data), และผลลัพธ์ (y) เข้าไป พร้อมกำหนด scoring เป็น "roc_auc" และ cv เป็น 3

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

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

# Create full pipeline
pipeline = ____([
                     ("____", ____),
                     ("____", ____),
                     ("____", ____),
                     ("____", ____)
                    ])

# Perform cross-validation
cross_val_scores = ____(____, ____, ____, ____="____", ____=____)

# Print avg. AUC
print("3-fold AUC: ", np.mean(cross_val_scores))
แก้ไขและรันโค้ด