Before you readA spam filter gives a message a score of −2. How can it turn that score into a probability?
Watch: Logistic regression · StatQuest with Josh Starmer
A classifier predicts a label. Use y=1 for spam and y=0 for not spam. Logistic regression first takes a dot product to give the message a score z=wTx+b. The sigmoid turns any real score into a probability:
p=P(y=1∣x)=σ(z)=1+e−z1.
A score of zero gives p=21. Positive scores push p towards 1; negative scores push it towards 0. The score is also the log-odds: log1−pp=z. Adding one to the score multiplies the odds by e.
z=x+b = -1p = 0.269Decision boundary: x = 2Prediction: not spam
Move the feature to follow the sigmoid. Change the bias to move the decision boundary: the dashed guides meet at probability 0.5.
If you predict spam whenever p≥0.5, the decision boundary is where wTx+b=0. With two features that is a straight line (for non-zero w). The sigmoid bends the probability curve, not the boundary in feature space.
To learn w and b, give each observed label as much probability as possible. The model gives label 1 probability p and label 0 probability 1−p.Maximising the product of these probabilities across training examples is equivalent to minimising the sum of their binary cross-entropy losses:
ℓ(y,p)=−ylogp−(1−y)log(1−p).
For a spam message, the loss is −logp. If the model confidently calls it not spam (p near zero), that loss is large.
Recall
At threshold 0.5, what equation defines the decision boundary?
Recall
What is the loss when the observed label is 0?
Exercise
For w=(2,−1)T,x=(1,3)T and b=0, find the score and the predicted label at threshold 0.5. Give the two numbers in that order.
Exercise
The model gives two messages spam probabilities 0.8 and 0.3. The first is spam and the second is not. What probability does the model give to both labels occurring together, treating the messages as independent?