From Line to Curve: A Plot Twist


Last time we met a very judgmental line - one that tried to predict the future. But now the stakes are different. We don’t want a number. We want a decision. Yes or no. Spam or not. Drama or peace.
So... can a curve judge?
Imagine trying to use linear regression to predict if an email is spam. You train it on some features (like how many times the word "free" appears), and get a predicted value like 2.3 or -1.5 - which doesn’t make sense. I want a simple YES or NO!
We don’t need a continuous value. We need a decision. And that’s where logistic regression steps in.
The Curve That Decides
At the heart of logistic regression is the sigmoid function. It takes any number and squishes it into a value between 0 and 1.
The sigmoid function looks like this:
Well, it really looks like this:
It takes the raw number from the regression line - which could be anything from -5 to 42 - and squishes it into a probability between 0 and 1. So instead of saying “2.7,” it says, “hey, there’s a 93% chance this is a 1.”
But the probability is just the lawyer - the threshold is the judge
By default, that threshold is set at 0.5 - a 50/50 call. But you can move that bar depending on how strict you want your judge to be.
In medical tests? You don’t wait for 90% certainty before sounding the alarm. Even a 30% chance of something awful? Red flag.
In spam filters? We’re picky. Anything below 0.8 might still be a real email from your boss.
Here it’s not just about math - it’s about context. The threshold decides how risky and cautious your model is allowed to be.
Lets try it out
Just like last time, X is still our feature (like hours studied), and y is the label (pass or fail). But this time, we’re not trying to predict a number - we’re trying to decide if I passed or failed.
# Step 1: Import the model
from sklearn.linear_model import LogisticRegression
import numpy as np
# Step 2 : Gather data, lets say this data is the hours studied vs pass/fail
X = np.array([1, 2, 3, 4, 5, 6]).reshape(-1, 1)
y = np.array([0, 0, 0, 1, 1, 1])
# Step 3: Initialize the model
model = LogisticRegression()
# Step 4: Fit the model
model.fit(X, y)
# Step 5: Make predictions
print(model.predict([[3.5]])) # Will return 0 or 1
print(model.predict_proba([[3.5]])) # Will return probabilities - the model’s confidence
# in each class.
# [0.2, 0.8] → 20% chance of 0, 80% chance of 1. That’s the sigmoid’s opinion.
Reshape(-1, 1) makes another cameo - because scikit-learn still expects your features to be dressed as 2D arrays. Habits die hard.
Where it falls apart
1. It assumes everything is linearly seperable
Logistic regression assumes that you can draw a line to split your data cleanly into two sides: class 0 on one side, class 1 on the other.
But real-world data is messy.
Let’s say you’re trying to classify students into "pass" or "fail" based on hours studied. Sounds doable. But what if some students study 10 hours and still fail? Or someone crams for 2 hours and passes because… luck? Coke?
Suddenly, the data isn’t neatly separable. Logistic regression tries its best, but it draws a straight boundary - and if your data twists, curves, or overlaps, it gets confused.
Technically speaking: it struggles when the classes aren’t linearly separable - which is very often the case.
2. It Only Thinks in Twos
Logistic regression lives in a binary world: 0 or 1, black or white, coffee or tea. But what if you need to classify an animal as a cat, dog, or penguin?
Suddenly, Logistic regression is like: ‘Wait, I only know cat and dog. What’s a penguin?’
(Yes, there’s multiclass versions, but that’s a different episode.)
3. It Gets Flustered by Outliers
Logistic regression tries to minimize log loss - which punishes confident wrong predictions. So when an outlier shows up (say, a person studied 100 hours and still failed), it panics and shifts the boundary.
That one chaotic data point? It can ruin everything. Like that one group project member who does absolutely nothing, but somehow still gets an equal grade (do not support).
4. It Needs You to Hold Its Hand
Logistic regression needs you to prep the data like a full-course meal.
Want it to catch something non-obvious, like “students who studied a lot AND slept well did better”? You better create that combo feature yourself.
Otherwise, it’ll miss it entirely.
It won’t discover hidden patterns - you have to hand them over. Preferably labeled and alphabetized.
5. It’s Confident - Even When It’s Wrong
Logistic regression will look you dead in the eye and say,
“I’m 97% sure this isn’t spam” -
then let a phishing link waltz right into your inbox.
But it’s not self-aware enough to know when it's been trained on bad or biased data.
So if you give it garbage, it’ll confidently serve you… polished garbage.
And if your threshold isn’t set thoughtfully, you might end up with topsy turvy results.
The way Logistic Regression calmly draws the line and says, “This side’s a yes, that one’s a no” - that’s more decisiveness than you, me, and anyone else in the world can exhibit.
So when in doubt, ask logistic regression. I can assure you it’ll take lesser time to decide whether you should order out or not. Leave the decision making to the professionals.
See ya for the next one!
Subscribe to my newsletter
Read articles from Saanvi Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
