Entropy กับ Gini index
ในแบบฝึกหัดนี้ จะเปรียบเทียบความแม่นยำบน test set ของ dt_entropy กับความแม่นยำของต้นไม้อีกต้นที่ชื่อ dt_gini โดยที่ dt_gini ถูกเทรนบนชุดข้อมูลเดียวกันด้วยพารามิเตอร์เดียวกันทุกประการ ยกเว้นเกณฑ์การวัดข้อมูล (information criterion) ซึ่งตั้งค่าเป็น gini index ผ่านคีย์เวิร์ด 'gini'
X_test, y_test, dt_entropy รวมถึง accuracy_gini ซึ่งเป็นค่าความแม่นยำบน test set ของ dt_gini มีพร้อมใช้งานใน workspace แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Machine Learning with Tree-Based Models in Python
คำแนะนำการฝึกหัด
- นำเข้า
accuracy_scoreจากsklearn.metrics - ทำนายป้ายกำกับของ test set ด้วย
dt_entropyแล้วกำหนดผลลัพธ์ให้กับy_pred - ประเมินความแม่นยำบน test set ของ
dt_entropyแล้วกำหนดผลลัพธ์ให้กับaccuracy_entropy - ตรวจสอบค่า
accuracy_entropyและaccuracy_gini
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import accuracy_score from sklearn.metrics
from ____.____ import ____
# Use dt_entropy to predict test set labels
____= ____.____(____)
# Evaluate accuracy_entropy
accuracy_entropy = ____(____, ____)
# Print accuracy_entropy
print(f'Accuracy achieved by using entropy: {accuracy_entropy:.3f}')
# Print accuracy_gini
print(f'Accuracy achieved by using the gini index: {accuracy_gini:.3f}')