ความสามารถในการอธิบายในโมเดลแบบต้นไม้

Explainable AI ด้วย Python

Fouad Trad

Machine Learning Engineer

Decision tree

  • หน่วยพื้นฐานของโมเดลแบบต้นไม้
  • ใช้สำหรับ regression และ classification
  • โครงสร้างคล้ายต้นไม้สำหรับการพยากรณ์
    • การตัดสินใจหลายขั้นตอน
    • แต่ละการตัดสินใจอิงตาม feature เดียว
  • อธิบายได้โดยธรรมชาติ

ภาพแสดง decision tree ที่แสดงวิธีการพยากรณ์จากเงื่อนไขหลายข้อ

Explainable AI ด้วย Python

Random forest

  • ประกอบด้วย decision tree จำนวนมาก
  • ใช้สำหรับ regression และ classification
  • ทำให้การตีความโดยตรงซับซ้อนขึ้น
  • Feature importance
    • วัดการลดความไม่แน่นอนในการพยากรณ์
    • แตกต่างจาก coefficient ในโมเดลเชิงเส้น

ภาพแสดง random forest เป็นกลุ่มของต้นไม้ที่รับข้อมูลและรวมผลการพยากรณ์เพื่อให้ผลลัพธ์สุดท้าย

Explainable AI ด้วย Python

ชุดข้อมูลการรับเข้าเรียน

GRE Score TOEFL Score University Rating SOP LOR CGPA Accept
337 118 4 4.5 4.5 9.65 1
324 107 4 4 4.5 8.87 1
316 104 3 3 3.5 8.00 1
322 110 3 3.5 2.5 8.67 1
314 103 2 2 3 8.21 0
X_train = data.drop(['Accept'], axis=1)
y_train = data['Accept']
Explainable AI ด้วย Python

การเทรนโมเดล

from sklearn.tree import DecisionTreeClassifier

tree_model = DecisionTreeClassifier() tree_model.fit(X_train, y_train)
print(tree_model.feature_importances_)
[0.17936982 0.08878744 0.04388924 
 0.0532897  0.07130751 0.56335628]
from sklearn.ensemble import RandomForestClassifier

forest_model = RandomForestClassifier() forest_model.fit(X_train, y_train)
print(forest_model.feature_importances_)
[0.25347149 0.17518662 0.06551317 
 0.06758647 0.07866478 0.35957747]
Explainable AI ด้วย Python

Feature importance

import matplotlib.pyplot as plt

plt.barh(X_train.columns, 
         tree_model.feature_importances_)
plt.title('Feature Importance - Decision Tree')
plt.show()

กราฟแท่งแนวนอนแสดง feature importance ที่ระบุว่า CGPA และ GRE score มีความสำคัญสูงสุด

import matplotlib.pyplot as plt

plt.barh(X_train.columns, 
         forest_model.feature_importances_)
plt.title('Feature Importance - Random Forest')
plt.show()

กราฟแท่งแนวนอนแสดง feature importance ที่ระบุว่า CGPA และ GRE score มีความสำคัญสูงสุด

Explainable AI ด้วย Python

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

Explainable AI ด้วย Python

Preparing Video For Download...