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
Many beginners get confused by the name “logistic regression”, because they think it predicts a number. It does not. It predicts a class, such as yes or no, and it also gives the probability of that class.
Ravindra Bagale's Tip – मराठी
“Logistic regression” हे नाव अनेक beginners ना गोंधळात टाकतं, कारण त्यांना वाटतं की हा model एखादा number predict करतो. तसं नाही. हा model yes किंवा no सारखा class predict करतो, आणि सोबत त्या class ची probability पण देतो.
Ravindra Bagale's Tip – हिंदी
“Logistic regression” नाम कई beginners को उलझा देता है, क्योंकि उन्हें लगता है कि यह कोई number predict करता है. ऐसा नहीं है. यह yes या no जैसी class predict करता है, और साथ में उस class की probability भी देता है.