ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Real-world regression project က Basic/Intermediate chapter ကနေ လေ့လာခဲ့တဲ့ step အားလုံးကို sequence အတိုင်း ချိတ်ဆက် run ရပါတယ် — Data Loading → Preprocessing (missing value, scaling) → Feature Engineering → Train/Test Split → Model Training (Linear Regression, Random Forest ကို compare) → Evaluation (R², cross-validation) → best model ကို select ခြင်း ဆိုတဲ့ full workflow ကို ကိုယ်တိုင် ဆောင်ရွက်ကြည့်ခြင်းက, concept တစ်ခုချင်းစီ ဘယ်လို ချိတ်ဆက် အသုံးချရမလဲ ဆိုတာကို solidify လုပ်ပေးပါလိမ့်မယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
House dataset (size, bedrooms, age, location) ကို — (1) missing value handle, (2) categorical feature ကို One-Hot Encoding, (3) numeric feature ကို scale, (4) 80/20 train/test split, (5) Linear Regression + Random Forest ၂ ခုကို train ပြီး compare, (6) cross-validation ဖြင့် ပိုတည်ငြိမ်တဲ့ estimate ရယူ, (7) best model ကို ရွေးချယ် ဆိုတဲ့ full pipeline ကို ကိုယ်တိုင် run ကြည့်ပါ.
အတူတူ ကြည့်မယ်
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.preprocessing import StandardScaler
# 1-3: preprocess, encode, scale (see Basic/Intermediate chapters)
# 4: split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# 5: train and compare models
lr = LinearRegression().fit(X_train, y_train)
rf = RandomForestRegressor(n_estimators=100, random_state=42).fit(X_train, y_train)
print(f"Linear Regression R^2: {lr.score(X_test, y_test):.2f}")
print(f"Random Forest R^2: {rf.score(X_test, y_test):.2f}")
# 6: cross-validate the better model
cv_scores = cross_val_score(rf, X, y, cv=5)
print(f"Random Forest CV mean: {cv_scores.mean():.2f}")Linear Regression R^2: 0.82
Random Forest R^2: 0.89
Random Forest CV mean: 0.87၅ မိနစ် စမ်းကြည့်
House price dataset (sample data ကိုယ်တိုင် create ပါ, ဒါမှမဟုတ် public dataset) ကို full pipeline အတိုင်း run ကြည့်ပြီး, model ၂ မျိုးကို compare ကာ final model ကို ရွေးချယ်ကြည့်ပါ။
သတိလေးတစ်ချက်
Production မှာ deploy မယ့် final model ကို data အားလုံး (train+test ပေါင်း) နဲ့ ပြန် train ရပါမယ် — evaluation အတွက်ပဲ train/test ခွဲထားခဲ့တာမို့, deployment model ကတော့ data ရရှိသလောက် အကုန် အသုံးချသင့်ပါတယ်.