Ravindra BagaleCourses & study guides मराठी Track your progress

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

  1. Print y.value_counts() before splitting.
  2. Use stratify=y for binary labels when possible.
  3. Keep features numeric (or encode categories explicitly).
  4. 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.