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

Linear Regression Deep Dive

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

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

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

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

Linear Regression ရဲ့ formula က `y = m*x + b` (school algebra ကနေ ရင်းနှီးမှာပါ) — `m` (coefficient/slope) က feature တစ်ခုချင်းစီရဲ့ 'ဘယ်လောက် weight' ရှိလဲ ကို ဖော်ပြပြီး, `b` (intercept) က feature အားလုံး 0 ဖြစ်တဲ့အခါ baseline value ကို ဖော်ပြပါတယ်။ Multiple Linear Regression ကတော့ feature တစ်ခုထက်ပို (`y = m1*x1 + m2*x2 + ... + b`) ကို handle လုပ်နိုင်ပါတယ် — house price ကို 'size' တစ်ခုတည်းမဟုတ်ဘဲ 'size + location + age' ဆိုပြီး feature များစွာနဲ့ predict ချင်ရင် ဒီ concept ကို သုံးရပါတယ်.

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

`model.coef_` ကို print ကြည့်ရင် feature တစ်ခုချင်းစီရဲ့ coefficient ကို ကြည့်နိုင်ပါတယ် — coefficient positive ဆိုရင် feature တိုးလာရင် target တိုးလာမယ် (positive correlation), negative ဆိုရင် feature တိုးလာရင် target ကျသွားမယ် (negative correlation) ဆိုတာ interpret လုပ်နိုင်ပါတယ် — 'size' coefficient က 'age' coefficient ထက် ကြီးရင် size က price ကို ပိုသက်ရောက်တယ်ဆိုတာ ခန့်မှန်းနိုင်ပါတယ်.

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

python
from sklearn.linear_model import LinearRegression

# Multiple features: size, age, distance to city center
X = df[['size', 'age', 'distance']]
y = df['price']

model = LinearRegression()
model.fit(X, y)

print(f"Coefficients: {model.coef_}")
print(f"Intercept: {model.intercept_}")
# e.g. Coefficients: [1200, -800, -3000]
# size: +1200 per unit, age: -800 per year, distance: -3000 per km
You should see
Coefficients: [1200.5  -800.2 -3000.1]
Intercept: 50000.0

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

Multiple feature (size, age, distance) ပါတဲ့ sample dataset ကို Multiple Linear Regression ဖြင့် train ကြည့်ပြီး, `model.coef_` ကို print ကာ feature တစ်ခုချင်းစီရဲ့ direction (positive/negative) ကို interpret ရေးကြည့်ပါ။

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

Multicollinearity (feature နှစ်ခု တစ်ခုနဲ့တစ်ခု correlate ကြီးမားနေခြင်း, ဥပမာ - 'size in sqft' နဲ့ 'size in sqm') ရှိရင် coefficient ကို reliably interpret မရနိုင်ပါ — redundant feature ကို remove လုပ်သင့်ပါတယ်.

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

  • Coefficient magnitude ကို feature ရဲ့ scale ထည့်မတွက်ဘဲ တိုက်ရိုက် နှိုင်းယှဉ်ခြင်း — feature scaling (Basic chapter) မလုပ်ရသေးရင် coefficient magnitude က feature ရဲ့ scale ကို ထင်ဟပ်နေတာဖြစ်နိုင်ပါတယ် (real importance မဟုတ်)
  • Correlation ကို causation နဲ့ ရောထင်ခြင်း — coefficient positive ဆိုတာ 'correlation' ကို ဖော်ပြတာပဲ, 'A ကြောင့် B ဖြစ်တယ်' ဆိုတဲ့ causation ကို သက်သေမပြပါ

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

Multiple feature (size, age, distance) ပါတဲ့ sample dataset ကို Multiple Linear Regression ဖြင့် train ကြည့်ပြီး, `model.coef_` ကို print ကာ feature တစ်ခုချင်းစီရဲ့ direction (positive/negative) ကို interpret ရေးကြည့်ပါ။

You'll know it worked when: Coefficients: [1200.5 -800.2 -3000.1] Intercept: 50000.0

Linear Regression Deep Dive | Thuta Learning