Soft voting เทียบกับ Hard voting
ตอนนี้ได้ฝึกสร้าง ensemble method สองแบบแล้ว ได้แก่ Voting และ Averaging (soft voting) แล้วแบบไหนดีกว่ากัน? วิธีที่ดีที่สุดคือลองทั้งสองแบบแล้วเปรียบเทียบประสิทธิภาพ มาลองทำกับชุดข้อมูล Game of Thrones กัน
มีตัวจำแนกเดี่ยวสามตัวถูกสร้างไว้ให้แล้ว:
DecisionTreeClassifier(clf_dt)LogisticRegression(clf_lr)KNeighborsClassifier(clf_knn)
ให้ลองใช้ทั้ง voting และ averaging เพื่อหาว่าแบบไหนให้ผลดีกว่า
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Ensemble Methods ใน Python
คำแนะนำการฝึกหัด
- เตรียมลิสต์ของ tuple แบบ
(string, estimator)โดยใช้'dt'เป็นป้ายกำกับของclf_dt,'lr'สำหรับclf_lrและ'knn'สำหรับclf_knn - สร้าง voting classifier ชื่อ
clf_vote - สร้าง averaging classifier ชื่อ
clf_avg
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# List of (string, estimator) tuples
estimators = ____
# Build and fit a voting classifier
clf_vote = ____
clf_vote.fit(X_train, y_train)
# Build and fit an averaging classifier
clf_avg = ____
clf_avg.fit(X_train, y_train)
# Evaluate the performance of both models
acc_vote = accuracy_score(y_test, clf_vote.predict(X_test))
acc_avg = accuracy_score(y_test, clf_avg.predict(X_test))
print('Voting: {:.2f}, Averaging: {:.2f}'.format(acc_vote, acc_avg))