34. Classification in Python with Logistic Regression
34.1 Why Yes/No or Category Problems
Why. Shops ask yes/no questions every day: will this order churn? Is this UPI transfer risky? Will the pedha tray sell out? Those answers are classes, not ₹ amounts.
What. Classification predicts a category. The simplest case is binary: 0/1 (no/yes). Logistic regression is a classic first classifier in sklearn — despite the name “regression,” the output you care about is a class (and a probability).
How.
Name the class problem
- Write y as clear labels: e.g.
sold_out= 1 if tray empty by 6 PM IST, else 0. - List features known before 6 PM (morning stock, weekday, temperature).
- Confirm you are not predicting a continuous ₹ total (that was Chapter 33).
import pandas as pd
orders = pd.DataFrame({
"morning_stock": [40, 25, 55, 30, 48],
"is_weekend": [0, 1, 0, 1, 0],
"sold_out": [1, 1, 0, 1, 0], # label
})
print(orders)
print("y is sold_out (class). X will be morning_stock + is_weekend.")
Ravindra Bagale's Tip
Logistic regression name confusing aahe — beginners “number predict karto” samajtat. Nahi: class + probability.