34. Logistic Regression ने Python मध्ये Classification
34.3 predict_proba सोप्या भाषेत
का गरजेचे आहे. फक्त 0/1 prediction probability सांगत नाही. Ops teams अनेकदा विचारतात “किती खात्री?” — ते predict_proba आहे.
हे काय आहे. binary problems साठी predict_proba(X) दोन columns देते: class 0 आणि class 1 ची probability. Default predict P(class 1) ≥ 0.5 असताना class 1 निवडते. False alarms महाग असतील तर नंतर वेगळा cutoff निवडता येतो.
कसे करायचे.
Probabilities वाचा
- काही rows वर predict_proba बोलावा.
- Class 1 चा column पाहा.
- Default 0.5 threshold वर predict शी तुलना करा.
# After clf.fit(...)
proba = clf.predict_proba(X_test)
print("P(class 0), P(class 1):\n", proba.round(3))
print("predict:", clf.predict(X_test))
# Manual threshold example: flag churn if P(1) >= 0.4
p1 = proba[:, 1]
print("custom flags @0.4:", (p1 >= 0.4).astype(int))
तुम्हाला काय दिसायला हवे. 0 आणि 1 मधील probabilities. 0.5 जवळचे rows “अनिश्चित”. Threshold बदलल्याने missed churns vs जास्त alerts यात व्यापार होतो — business निर्णय, जादू नाही.
Ravindra Bagale's Tip
A probability of 0.51 does not mean the result is guaranteed. It only means the model is a little more sure than unsure. Choose your threshold based on the business cost of a wrong prediction, and do not depend only on the default value of 0.5.
Ravindra Bagale's Tip – मराठी
0.51 probability चा अर्थ निकाल नक्की आहे असा होत नाही. त्याचा अर्थ एवढाच की model थोड्याशा जास्त खात्रीने सांगत आहे. चुकीच्या prediction मुळे business चं किती नुकसान होईल यावरून threshold ठरवा, फक्त default 0.5 वर अवलंबून राहू नका.
Ravindra Bagale's Tip – हिंदी
0.51 probability का मतलब यह नहीं कि नतीजा पक्का है. इसका मतलब बस इतना है कि model थोड़ा सा ज़्यादा यकीन से कह रहा है. गलत prediction से business को कितना नुकसान होगा, उसके आधार पर threshold तय करो, सिर्फ़ default 0.5 पर निर्भर मत रहो.