ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Hyperparameter ဆိုတာ model က data ကနေ learn လုပ်တဲ့ parameter (coefficient) မဟုတ်ဘဲ, developer/data scientist က training မစခင် ကြိုတင်သတ်မှတ်ပေးရတဲ့ setting ပါ (ဥပမာ - `max_depth`, `n_estimators`, `K`)။ Grid Search ကတော့ hyperparameter combination အားလုံးကို systematically စမ်းကြည့်ပြီး (ဥပမာ - `max_depth: [3,5,7]` × `n_estimators: [50,100,200]` = combination 9 ခု), cross-validation (Intermediate chapter) ဖြင့် combination တစ်ခုချင်းစီရဲ့ performance ကို evaluate ကာ, best combination ကို auto-select ပေးပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
`from sklearn.model_selection import GridSearchCV; params = {'max_depth': [3,5,7], 'n_estimators': [50,100,200]}; grid = GridSearchCV(RandomForestClassifier(), params, cv=5); grid.fit(X_train, y_train)` လို့ ရေးရင် — combination 9 ခုကို cross-validation ဖြင့် တစ်ခုချင်းစီ evaluate ပြီး, `grid.best_params_` ကို ကြည့်ရင် ဘယ် combination က performance ပိုကောင်းလဲ ချက်ချင်း သိနိုင်ပါတယ်.
အတူတူ ကြည့်မယ်
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import RandomForestClassifier
param_grid = {
'max_depth': [3, 5, 7],
'n_estimators': [50, 100, 200]
}
grid = GridSearchCV(RandomForestClassifier(random_state=42), param_grid, cv=5)
grid.fit(X_train, y_train)
print(f"Best parameters: {grid.best_params_}")
print(f"Best cross-validation score: {grid.best_score_:.2f}")Best parameters: {'max_depth': 7, 'n_estimators': 200}
Best cross-validation score: 0.89၅ မိနစ် စမ်းကြည့်
Random Forest ကို `GridSearchCV` ဖြင့် `max_depth`/`n_estimators` combination အနည်းငယ် စမ်းကြည့်ပါ — `best_params_` ရလဒ်ကို manual default value နဲ့ compare ကြည့်ပါ။
သတိလေးတစ်ချက်
Hyperparameter tuning ကို 'model performance ကို guaranteed တိုးစေမယ့် magic' လို့ မထင်ပါနှင့် — data quality/feature engineering (Intermediate chapter) က often hyperparameter tuning ထက် ပိုအရေးကြီးပါတယ်.