ประสิทธิภาพที่ดีขึ้นด้วย Voting Classifier
ในขั้นตอนสุดท้าย จะประเมินประสิทธิภาพของ Voting Classifier ที่รับผลลัพธ์จากโมเดลที่กำหนดไว้ในลิสต์ classifiers แล้วกำหนด label โดยใช้การโหวตเสียงข้างมาก
X_train, X_test, y_train, y_test, ลิสต์ classifiers ที่กำหนดไว้ในแบบฝึกหัดก่อนหน้า รวมถึงฟังก์ชัน accuracy_score จาก sklearn.metrics พร้อมใช้งานใน workspace แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Machine Learning with Tree-Based Models in Python
คำแนะนำการฝึกหัด
- Import
VotingClassifierจากsklearn.ensemble - สร้าง
VotingClassifierโดยกำหนดพารามิเตอร์estimatorsเป็นclassifiersแล้วกำหนดให้กับตัวแปรvc - Fit
vcกับชุดข้อมูล training - ประเมินความแม่นยำของ
vcบนชุดข้อมูล test โดยใช้ค่าที่ทำนายได้y_pred
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import VotingClassifier from sklearn.ensemble
____
# Instantiate a VotingClassifier vc
vc = ____(estimators=____)
# Fit vc to the training set
____.____(____, ____)
# Evaluate the test set predictions
y_pred = vc.predict(X_test)
# Calculate accuracy score
accuracy = ____(____, ____)
print('Voting Classifier: {:.3f}'.format(accuracy))