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

การประมวลผลข้อมูลภายใน Pipeline

หลังจากที่เห็นแล้วว่าต้องทำขั้นตอนใดบ้างเพื่อประมวลผลข้อมูลบ้าน Ames ให้ถูกต้อง คราวนี้มาลองใช้ DictVectorizer ซึ่งกระชับและสะอาดกว่า แล้วนำไปใช้ร่วมกับ XGBoostRegressor ภายใน scikit-learn pipeline กัน

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

Extreme Gradient Boosting with XGBoost

ดูคอร์ส

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

  • นำเข้า DictVectorizer จาก sklearn.feature_extraction และ Pipeline จาก sklearn.pipeline
  • เติมค่าที่ขาดหายไปในคอลัมน์ LotFrontage ของ X ด้วย 0
  • กำหนดขั้นตอนใน pipeline โดยใช้ DictVectorizer(sparse=False) สำหรับ "ohe_onestep" และ xgb.XGBRegressor() สำหรับ "xgb_model"
  • สร้าง pipeline โดยใช้ Pipeline() และ steps
  • ฝึก pipeline อย่าลืมแปลง X ให้อยู่ในรูปแบบที่ DictVectorizer เข้าใจได้ โดยเรียกเมธอด to_dict("records") บน X

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

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

# Import necessary modules
____
____

# Fill LotFrontage missing values with 0
X.LotFrontage = ____

# Setup the pipeline steps: steps
steps = [("ohe_onestep", ____),
         ("xgb_model", ____)]

# Create the pipeline: xgb_pipeline
xgb_pipeline = ____

# Fit the pipeline
____
แก้ไขและรันโค้ด