The name "Logistic regression" is misleading.
Logistic regression is not used to predict values like price or temperature (like in regression problems).
It is used when the final answer is a label.
The model always give a probability value, and using that value we decide the category.
The Probability values ends up making decisions like the following.
Logistic regression is used when the final outcome has only two possible choices. The model does not directly say yes or no. Instead, it first calculates how likely one outcome is compared to the other. Based on this likelihood, a final decision is made.
Before making any decision, the model calculates a simple score called z. This score is only a number. It may be negative, zero, or positive. At this stage, the model is not predicting a class. It is only measuring which side the situation is leaning toward.
The score z by itself is not very useful. It can be any number, like −5, 2, or even 20. But for classification, we need something meaningful. So the model converts z into a probability between 0 and 1. This conversion is done using a function called sigmoid.
After applying the sigmoid function, the model produces a probability p. This value tells us how strongly the model believes the input belongs to class 1. To turn this probability into a final label, we choose a cutoff value called the threshold.
Let us work through one complete example of logistic regression for spam detection. In this example, an email is either accepted to the inbox or sent to spam.
In a real spam filter, the equation used to calculate z is not chosen by hand. It is learned by training the computer using data.
During training, the model is shown thousands of emails that are already labelled as Spam or Not spam. For each email, the computer extracts features (numbers), predicts a label, compares with the correct label, and measures the error.
When the prediction is wrong, the model adjusts the constants in its formula. This adjustment is done using optimisation techniques. The most common one is gradient descent, where the model repeatedly reduces its errors step by step. Other optimisation methods are also used in practice, but the idea is always the same: improve the model by learning from errors.
After training on many spam and normal emails, the model settles on values that work well. That is how an equation like the one below is obtained.
For each email, we count how many of these words appear. Let x be that count. The model does not understand the “meaning” of the message. It only uses this number.
| Email (short) | x | z | p | Result |
|---|---|---|---|---|
| Meeting at 3 pm. Agenda attached. | 0 | −4.0 | ≈ 0.02 | Inbox |
| Invoice sent. Please review and reply. | 0 | −4.0 | ≈ 0.02 | Inbox |
| Limited offer. Click now for discount. | 4 | 0.8 | ≈ 0.69 | Inbox |
| Urgent: claim your reward now. | 3 | −0.4 | ≈ 0.40 | Inbox |
| Buy cheap deal today. Limited bonus. | 5 | 2.0 | ≈ 0.88 | Inbox |
| Win cash prize now. Click to claim. | 6 | 3.2 | ≈ 0.96 | Spam |
| Congratulations winner! Claim your gift. | 4 | 0.8 | ≈ 0.69 | Inbox |
| Jackpot prize! Win money now. | 5 | 2.0 | ≈ 0.88 | Inbox |
| Free bonus cash. Limited time. Click now. | 6 | 3.2 | ≈ 0.96 | Spam |
| Claim jackpot reward. Win prize now. | 6 | 3.2 | ≈ 0.96 | Spam |
Now let us to do logistic regression using a real weather idea from Texas.
We are not trying to predict the exact rainfall amount.
We only want a two label answer either
Wet May or Not a Wet May.
Note: Logistic Regression is used to make Binary Decisions
Using this historical data, each May was labelled as: Wet or Not Wet.
During training, the computer adjusts the constants so the model separates “wet” versus “not wet” Mays as well as it can using the 1995–2025 data. After fitting the model, suppose the learned score equation is:
The score z is not a probability yet. We convert it into a probability using the sigmoid function:
For May 2025, our input is x = 8.