Despite its name, logistic regression is a classification model. It answers yes/no questions: will this customer leave, is this email spam, will this loan be repaid? It is often the first classification model data science learners meet, and it is still widely used at work because it is fast and easy to explain.
From a straight line to a probability
Linear regression draws a straight line and can predict any number, including values below 0 or above 1. That does not make sense for a probability. Logistic regression passes the linear result through an S-shaped curve called the sigmoid, which squeezes every value into the range 0 to 1.
The output is a probability, such as 0.82. You then choose a threshold, commonly 0.5, to turn it into a yes or no.
Reading the coefficients
Each input feature gets a coefficient. A positive coefficient pushes the probability up, a negative one pushes it down. For a churn model, a positive coefficient on “number of complaints” means more complaints are linked to a higher chance of leaving. This explainability is why business teams like the model.
Choosing the threshold
0.5 is not always right. If missing a positive case is costly (for example, failing to flag fraud), lower the threshold to catch more cases and accept more false alarms. If false alarms are costly, raise it. Look at precision and recall at several thresholds before deciding.
A minimal example in Python
from sklearn.linear_model import LogisticRegression
model = LogisticRegression(max_iter=1000)
model.fit(X_train, y_train)
probs = model.predict_proba(X_test)[:, 1]
Scale numeric features first, and encode categories as numbers, for example with one-hot encoding.
When to use it
- As a baseline before trying more complex models.
- When you need to explain predictions to non-technical people.
- When the data is not huge and relationships are roughly linear.
Next, read why accuracy is not enough and classification models for beginners.
Machine learning models like this one are covered with projects in our Data Science course in Bangalore.
Book a free demo class at our BTM Layout centre, and ask a counsellor for batch details.
