34. Classification in Python with Logistic Regression
34.3 predict_proba Explained Simply
Why. A hard 0/1 is blunt. Ops teams often want “how sure?” — that is predict_proba.
What. predict_proba(X) returns two columns for binary problems: probability of class 0 and class 1. Default predict picks class 1 when P(class 1) ≥ 0.5. You can choose a different cutoff later if false alarms are costly.
How.
Read probabilities
- Call
predict_probaon a few rows. - Look at the column for class 1.
- Compare with
predictat the default 0.5 threshold.
# 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))
What you should see. Probabilities between 0 and 1. Rows near 0.5 are “unsure.” Changing the threshold trades missed churns vs too many alerts — business choice, not magic.
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 पर निर्भर मत रहो.