Thuta Learning
ရှာဖွေရန်
IntermediateData & Databasesintermediate

Decision Trees

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Decision Trees ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် scikit-learn code ကို run ကြည့်တတ်မယ်
  • Real project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

Decision Tree က data ကို question (ဥပမာ - 'age > 30?') series ဖြင့် ခွဲခြားပြီး, leaf node ရောက်တဲ့အထိ decision ချသွားတဲ့ tree structure ပါ — human-readable ဖြစ်လို့ (Linear Regression ရဲ့ coefficient ထက်) 'ဘာကြောင့် ဒီ prediction ချသလဲ' ဆိုတာ ရှင်းရှင်းလင်းလင်း explain လုပ်နိုင်ပါတယ်။ Tree ရဲ့ depth (question layer အရေအတွက်) ကို ကန့်သတ်မထားရင် — training data ကို 'အလွတ်ကျက်' လောက်အောင် deep ဖြစ်သွားနိုင်ပါတယ် (overfitting risk), `max_depth` parameter ဖြင့် ကန့်သတ်ပေးရပါတယ်.

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

`from sklearn.tree import DecisionTreeClassifier; model = DecisionTreeClassifier(max_depth=5); model.fit(X_train, y_train)` လို့ ရေးရင် — tree depth ကို 5 layer ထိသာ ခွင့်ပြုထားလို့ overfitting ကို ကန့်သတ်ပေးပါတယ်, `from sklearn.tree import plot_tree; plot_tree(model)` ကို run ရင် tree structure ကို visual diagram အနေနဲ့ ကြည့်နိုင်ပါတယ် — 'ဘယ် feature ကို ဘယ် threshold မှာ ခွဲခြားလဲ' ဆိုတာ ရှင်းရှင်းလင်းလင်း တွေ့ရမှာပါ.

အတူတူ ကြည့်မယ်

python
from sklearn.tree import DecisionTreeClassifier, plot_tree
import matplotlib.pyplot as plt

model = DecisionTreeClassifier(max_depth=5, random_state=42)
model.fit(X_train, y_train)

print(f"Accuracy: {model.score(X_test, y_test):.2f}")

# Visualize the tree structure
plot_tree(model, feature_names=X.columns, filled=True)
plt.show()
You should see
Accuracy: 0.84

၅ မိနစ် စမ်းကြည့်

Decision Tree Classifier ကို sample dataset ဖြင့် train ကြည့်ပြီး, `max_depth` ကို 2, 5, None (unlimited) ဆိုပြီး ကွဲပြားစွာ ချကာ accuracy ကို compare ကြည့်ပါ — depth ကြီးလွန်းရင် ဘာဖြစ်လဲ observe လုပ်ကြည့်ပါ။

သတိလေးတစ်ချက်

Decision Tree ရဲ့ interpretability (ရှင်းလင်းပြီး explain လုပ်ရလွယ်ခြင်း) ကို prioritize ရမယ့် use case (ဥပမာ - loan approval, medical decision, regulation-heavy industry) မှာ Decision Tree က black-box algorithm (Neural Network) ထက် ပိုသင့်တော်နိုင်ပါတယ်.

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • `max_depth` ကို ကန့်သတ်မထားဘဲ tree ကို 'unlimited' depth ဖြင့် train ခြင်း — training accuracy 100% ရနိုင်ပေမယ့် test accuracy ကျဆင်းနိုင်ပါတယ် (overfitting)
  • Decision Tree တစ်ခုတည်း ရလဒ်ကို ပြီးပြည့်စုံပြီလို့ ယူဆခြင်း — single tree က unstable ဖြစ်တတ်ပါတယ် (data အနည်းငယ် ပြောင်းရင် tree structure သိသိသာသာ ကွဲသွားနိုင်), Random Forest (Advanced chapter) က ဒီ weakness ကို ဖြေရှင်းပေးပါတယ်

အခု ကိုယ်တိုင် စမ်းကြည့်

Decision Tree Classifier ကို sample dataset ဖြင့် train ကြည့်ပြီး, `max_depth` ကို 2, 5, None (unlimited) ဆိုပြီး ကွဲပြားစွာ ချကာ accuracy ကို compare ကြည့်ပါ — depth ကြီးလွန်းရင် ဘာဖြစ်လဲ observe လုပ်ကြည့်ပါ။

You'll know it worked when: Accuracy: 0.84

Decision Trees | Thuta Learning