เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การใช้ entropy เป็น criterion

ในแบบฝึกหัดนี้ จะได้ฝึก classification tree บนชุดข้อมูล Wisconsin Breast Cancer โดยใช้ entropy เป็น information criterion โดยใช้ฟีเจอร์ทั้ง 30 ตัวในชุดข้อมูล ซึ่งแบ่งเป็นข้อมูล train 80% และ test 20%

X_train และอาร์เรย์ของ label y_train พร้อมใช้งานใน workspace แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Machine Learning with Tree-Based Models in Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Import DecisionTreeClassifier จาก sklearn.tree

  • สร้าง DecisionTreeClassifier ชื่อ dt_entropy โดยกำหนด maximum depth เป็น 8

  • ตั้งค่า information criterion เป็น 'entropy'

  • Fit dt_entropy บนชุดข้อมูล training

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Import DecisionTreeClassifier from sklearn.tree
from ____.____ import ____

# Instantiate dt_entropy, set 'entropy' as the information criterion
dt_entropy = ____(____=____, ____='____', random_state=1)

# Fit dt_entropy to the training set
____.____(____, ____)
แก้ไขและรันโค้ด