Data Science

Classification with Logistic Regression

SQL Mastery Team
June 15, 2026
5 min read

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

  • **Medical**: Does this patient have the disease? (Yes/No)
  • **Marketing**: Is this user going to open the email? (Open/Ignore)
  • **Finance**: Is this credit card application risky? (Approve/Deny)
  • 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.*

    Ready to put your knowledge into practice?

    Join SQL Mastery and learn through interactive exercises.