33. sklearn सह Python मध्ये Linear Regression
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 वाचा
model.intercept_आणिmodel.coef_print करा.- प्रत्येक coef ला त्याच्या column नावाशी जोडा.
- ₹ मध्ये एक 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.
Ravindra Bagale's Tip – मराठी
coef_ च्या values ना विचार न करता importance ranking समजू नका. Coefficient किती मोठा आहे हे प्रत्येक feature च्या unit वर अवलंबून असतं. उदाहरणार्थ, square feet मधला area आणि 0/1 flag यांचे units खूप वेगळे आहेत, त्यामुळे त्यांच्या coefficients ची थेट तुलना करता येत नाही.
Ravindra Bagale's Tip – हिंदी
coef_ की values को बिना सोचे importance ranking मत समझो. Coefficient कितना बड़ा है, यह हर feature की unit पर निर्भर करता है. उदाहरण के लिए, square feet में area और 0/1 flag की units बहुत अलग हैं, इसलिए उनके coefficients की सीधी तुलना नहीं की जा सकती.