Cost-Sensitive Learning for logistic regression
Logistic regression is a simple classification algorithm. We train a model as a linear combination of the features. Then, we pass the result of that linear combination into a sigmoid function to predict the class probabilities for different classes.
The sigmoid
function (also called a logit
function) is a mathematical tool capable of converting any real number into a value between 0 and 1. This value can be interpreted as a probability estimate:
import numpy as np def sigmoid(x): s = 1/(1+np.exp(-x)) return s
The graph of the sigmoid function has an S-shaped curve, and it appears like this:
Figure 5.4 – Sigmoid function
The class with the highest predicted probability is taken as the prediction for a given sample.
Let’s say we have an email to be classified as spam or non-spam, and our logistic regression model outputs the...