34. Classification in Python with Logistic Regression
34.4 Thresholds and Class-Balance Mistakes
Why. Classification notebooks fail quietly when labels are flipped, classes are tiny, or text cities are fed raw without encoding.
What. Watch for: predicting the majority class and calling it success; skipping stratify on rare fraud labels; using LinearRegression on 0/1 y; forgetting that city names need encoding before most sklearn models.
How.
Quick guards
- Print
y.value_counts()before splitting. - Use
stratify=yfor binary labels when possible. - Keep features numeric (or encode categories explicitly).
- Do not celebrate accuracy alone on 95% “not churn” data — Chapter 37.
print(y.value_counts())
# If one class has only 1–2 rows, get more data before trusting metrics.
Ravindra Bagale's Tip
“Sab predict 0” model accuracy high disu shakte — useless. Class balance bagha.