ป่าแห่ง Decision Tree
ในแบบฝึกหัดนี้ จะได้ฝึกใช้ Decision Tree แบบ bootstrapped ที่รู้จักกันในชื่อ Random Forest จากนั้นเปรียบเทียบความแม่นยำกับโมเดลที่ปรับ hyperparameter ด้วย cross-validation เหมือนที่ทำในแบบฝึกหัดก่อนหน้า
คราวนี้จะมีการปรับ hyperparameter เพิ่มเติมอีกตัว คือ max_features ซึ่งกำหนดจำนวน feature ที่โมเดลจะนำมาใช้ หากไม่ได้ระบุค่าไว้ ค่าเริ่มต้นจะเป็น auto สิ่งที่ควรจำสำหรับการสัมภาษณ์คือ Decision Tree จะพิจารณา feature ทั้งหมดโดยค่าเริ่มต้น ในขณะที่ Random Forest มักพิจารณาเพียงรากที่สองของจำนวน feature
ได้มีการนำเข้า feature matrix X, target label y และ train_test_split จาก sklearn.model_selection ไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
ฝึกตอบคำถามสัมภาษณ์ Machine Learning ด้วย Python
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import modules
from sklearn.ensemble import ____
from sklearn.metrics import accuracy_score
# Train/test split
X_train, X_test, y_train, y_test = train_test_split(____, ____, test_size=0.30, random_state=123)
# Instantiate, Fit, Predict
loans_rf = ____()
loans_rf.____(____, ____)
y_pred = loans_rf.____(____)
# Evaluation metric
print("Random Forest Accuracy: {}".format(____(____,____)))