Decision Trees၊ Random Forests နှင့် Boosting
scikit-learn 1.9.1
Tree-based baseline ရွေးပြီး ensemble method က estimator တွေကို ဘယ်လို ပေါင်းလဲ နားလည်ပါ။
ဒီစာမျက်နှာမှာ
Tree ရှုပ်ထွေးမှုကို ထိန်းခြင်း
Decision tree က feature နဲ့ threshold အလိုက် ခွဲပုံ သင်ယူပါတယ်။ Tree အရမ်းနက်ရင် overfit ဖြစ်နိုင်ပါတယ်။ max_depth သို့မဟုတ် min_samples_leaf လို parameter နဲ့ ထိန်းပြီး training အပြင်က data ပေါ် အကဲဖြတ်ပါ။
ပျမ်းမျှယူခြင်းနှင့် အဆင့်လိုက် ပြင်ခြင်း ယှဉ်ခြင်း
Random forest က randomize လုပ်ထားတဲ့ tree အများကြီးရဲ့ result ပျမ်းမျှယူပါတယ်။ Gradient boosting က loss နည်းလာဖို့ tree တွေ အစဉ်လိုက် ထပ်ထည့်ပါတယ်။ Validation plan တူတူနဲ့ ရိုးရှင်းတဲ့ baseline ကိုပါ ယှဉ်ပါ။
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)
model = RandomForestClassifier(n_estimators=30, max_depth=4, random_state=42)
model.fit(X_train, y_train)
print(len(model.estimators_))
print(model.score(X_test, y_test) > 0.8)
နမူနာ ရလဒ်
30 True