สร้าง instance ของโมเดล
ในชุดแบบฝึกหัดต่อไปนี้ คุณจะวินิจฉัยปัญหา bias และ variance ของ regression tree โดย regression tree ที่กำหนดในแบบฝึกหัดนี้จะนำไปใช้ทำนายอัตราการสิ้นเปลือง mpg ของรถยนต์จากชุดข้อมูล auto โดยใช้ทุก feature ที่มีอยู่
ข้อมูลได้รับการประมวลผลแล้ว และโหลด feature matrix X กับ array y ไว้ใน workspace ให้แล้ว นอกจากนี้ยังได้ import คลาส DecisionTreeRegressor จาก sklearn.tree มาให้เรียบร้อยแล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Machine Learning with Tree-Based Models in Python
คำแนะนำการฝึกหัด
- Import
train_test_splitจากsklearn.model_selection - แบ่งข้อมูลเป็น train 70% และ test 30%
- สร้าง instance ของ
DecisionTreeRegressorโดยกำหนด max depth เป็น 4 และตั้งค่าmin_samples_leafเป็น 0.26
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import train_test_split from sklearn.model_selection
____
# Set SEED for reproducibility
SEED = 1
# Split the data into 70% train and 30% test
X_train, X_test, y_train, y_test = ____(____, ____, test_size=____, random_state=SEED)
# Instantiate a DecisionTreeRegressor dt
dt = ____(____=____, ____=____, random_state=SEED)