การประมวลผลข้อมูลภายใน 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
____