Classification with Logistic Regression
Welcome to **Day 145**. Today we solve "Yes/No" problems.
What is Logistic Regression?
Unlike Linear Regression (which predicts a line), Logistic Regression predicts a **Probability** between 0 and 1. If the probability is > 0.5, we label it "Yes."
The Code
from sklearn.linear_model import LogisticRegression
# Predict if someone will buy (1) or not (0)
X = df[['time_on_site', 'pages_visited']]
y = df['bought']
model = LogisticRegression()
model.fit(X_train, y_train)
# Predict for a new user
new_user = [[10, 5]] # 10 mins, 5 pages
prob = model.predict_proba(new_user)
print(f"Probability of Buying: {prob[0][1]}")
Perfect Use Cases
Your Task for Today
Build a simple Logistic Regression model to predict a binary outcome (0 or 1) in your sample data.
*Day 146: Evaluating Models: R-Squared and Accuracy.*