Ravindra BagaleCourses & study guides English Track your progress

33. sklearn सह Python मध्ये Linear Regression

Data Science

33.4 coef_ आणि intercept_ वाचणे

का गरजेचे आहे. fit नंतर managers विचारतात “model ने काय शिकले?” तुम्ही सोप्या शब्दांत coef_ आणि intercept_ ने उत्तर द्या.

हे काय आहे. model.coef_ एक array आहे — प्रत्येक feature column साठी एक number. model.intercept_ एक सुरुवातीची value आहे. चिन्हे महत्त्वाची: positive coef म्हणजे सरासरी “feature वर → prediction वर” (linear model मध्ये इतर features ठेवून).

कसे करायचे.

शिकलेले numbers वाचा

  1. model.intercept_ आणि model.coef_ print करा.
  2. प्रत्येक coef ला त्याच्या column नावाशी जोडा.
  3. ₹ मध्ये एक business वाक्य सांगा.
# Continue after model.fit(...) from 33.3
print("intercept_:", round(model.intercept_, 2))
print("coef_ area_sqft:", round(model.coef_[0], 2))

# Two-feature toy: area + is_metro (1 = Pune/Mumbai tier in fiction)
df2 = pd.DataFrame({
 "area_sqft": [500, 700, 900, 500, 700, 900],
 "is_metro": [1, 1, 1, 0, 0, 0],
 "rent_inr": [16000, 20000, 24000, 11000, 14000, 17000],
})
X2 = df2[["area_sqft", "is_metro"]]
y2 = df2["rent_inr"]
m2 = LinearRegression().fit(X2, y2)
for name, c in zip(X2.columns, m2.coef_):
 print(name, "->", round(c, 2))
print("intercept_:", round(m2.intercept_, 2))

तुम्हाला काय दिसायला हवे. area वर positive coef (जास्त sqft → जास्त rent) आणि is_metro वर positive coef (metro flag ₹ वाढवते). नेमके आकडे छोट्या sample वर अवलंबून — digits पाठ करू नका, story समजा.

Ravindra Bagale's Tip

Do not treat the coef_ values as an importance ranking without thinking. The size of a coefficient depends on the unit of each feature. For example, area in square feet and a 0/1 flag use very different units, so you cannot compare their coefficients directly.