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
Probability 0.51 mhanje “guaranteed” nahi. Threshold business cost var decide kara.