ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Ensemble Method ဆိုတာ model (weak learner) များစွာကို ပေါင်းစပ်ပြီး, individual model တစ်ခုထက် ပိုတည်ငြိမ်/accurate ဖြစ်တဲ့ prediction ရအောင် လုပ်တဲ့ technique ပါ — 'crowd wisdom' concept နဲ့ ဆင်တူပါတယ် (opinion များစွာရဲ့ average က individual opinion တစ်ခုတည်းထက် ပိုတည်ငြိမ်တတ်တာလိုမျိုး)။ Random Forest ကတော့ Decision Tree (Intermediate chapter) များစွာကို bagging technique (data/feature ကို random sample ယူပြီး tree တစ်ခုချင်းစီကို train) ဖြင့် ပေါင်းစပ်ထားတဲ့ ensemble algorithm ပါ — final prediction ကို tree အားလုံးရဲ့ majority vote (classification) ဒါမှမဟုတ် average (regression) ဖြင့် ဆုံးဖြတ်ပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
`from sklearn.ensemble import RandomForestClassifier; model = RandomForestClassifier(n_estimators=100, max_depth=5); model.fit(X_train, y_train)` လို့ ရေးရင် — tree 100 ခုကို train ပြီး (`n_estimators=100`), test data ကို predict ချတဲ့အခါ tree 100 ခုစလုံးရဲ့ vote ကို ပေါင်းစပ်ပါတယ် — single Decision Tree ထက် ပိုတည်ငြိမ်ပြီး, overfitting risk ကလည်း နည်းပါတယ်.
အတူတူ ကြည့်မယ်
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
tree = DecisionTreeClassifier(max_depth=5, random_state=42)
tree.fit(X_train, y_train)
forest = RandomForestClassifier(n_estimators=100, max_depth=5, random_state=42)
forest.fit(X_train, y_train)
print(f"Single tree accuracy: {tree.score(X_test, y_test):.2f}")
print(f"Random Forest accuracy: {forest.score(X_test, y_test):.2f}")Single tree accuracy: 0.84
Random Forest accuracy: 0.91၅ မိနစ် စမ်းကြည့်
Single Decision Tree vs Random Forest ကို dataset တစ်ခုတည်းအပေါ် train/compare ကြည့်ပြီး, accuracy improvement ကို confirm လုပ်ကြည့်ပါ — `model.feature_importances_` ကို ပါ ကြည့်ကြည့်ပါ (feature တစ်ခုချင်းစီရဲ့ importance ranking).
သတိလေးတစ်ချက်
Random Forest ရဲ့ default hyperparameter (`n_estimators`, `max_depth`) ကို dataset အလိုက် tune မလုပ်ဘဲ 'default ကတော့ ကောင်းလောက်ပြီ' လို့ ယူဆခြင်းသည် — Advanced chapter ရဲ့ Hyperparameter Tuning lesson ကို ဆက်လေ့လာသင့်ပါတယ်.