Decision Tree สำหรับการจำแนกประเภท

Machine Learning with Tree-Based Models in Python

Elie Kawerk

Data Scientist

ภาพรวมคอร์ส

  • บทที่ 1: Classification And Regression Tree (CART)

  • บทที่ 2: The Bias-Variance Tradeoff

  • บทที่ 3: Bagging and Random Forests

  • บทที่ 4: Boosting

  • บทที่ 5: Model Tuning

Machine Learning with Tree-Based Models in Python

Classification Tree

  • ชุดคำถาม if-else เกี่ยวกับ feature แต่ละตัว

  • เป้าหมาย: อนุมาน class label

  • จับความสัมพันธ์แบบ non-linear ระหว่าง feature และ label ได้

  • ไม่จำเป็นต้องปรับสเกล feature (เช่น Standardization ฯลฯ)

Machine Learning with Tree-Based Models in Python

ชุดข้อมูลมะเร็งเต้านมใน 2D

ชุดข้อมูลมะเร็งเต้านมใน 2D

Machine Learning with Tree-Based Models in Python

แผนภาพ Decision Tree

แผนภาพ CART

Machine Learning with Tree-Based Models in Python

Classification Tree ใน scikit-learn

# Import DecisionTreeClassifier
from sklearn.tree import DecisionTreeClassifier
# Import train_test_split
from sklearn.model_selection import train_test_split
# Import accuracy_score
from sklearn.metrics import accuracy_score

# Split the dataset into 80% train, 20% test X_train, X_test, y_train, y_test= train_test_split(X, y, test_size=0.2, stratify=y, random_state=1)
# Instantiate dt dt = DecisionTreeClassifier(max_depth=2, random_state=1)
Machine Learning with Tree-Based Models in Python

Classification Tree ใน scikit-learn

# Fit dt to the training set
dt.fit(X_train,y_train) 

# Predict the test set labels
y_pred = dt.predict(X_test)

# Evaluate the test-set accuracy accuracy_score(y_test, y_pred)
0.90350877192982459
Machine Learning with Tree-Based Models in Python

Decision Region

Decision region: บริเวณในพื้นที่ feature ที่ instance ทุกตัวถูกกำหนดให้เป็น class label เดียวกัน

Decision Boundary: พื้นผิวที่แบ่ง decision region ที่แตกต่างกัน

Decision Region

Machine Learning with Tree-Based Models in Python

Decision Region: CART เทียบกับโมเดลเชิงเส้น

Logistic Regression เทียบกับ Decision Tree

Machine Learning with Tree-Based Models in Python

มาฝึกกันเถอะ!

Machine Learning with Tree-Based Models in Python

Preparing Video For Download...