# Linear regression
# Logistic regression
Logistic regression is used for classification. There are two steps: choose the form of the decision boundary, then find the coefficients that minimise the loss.
The classification problem
The sigmoid function maps a score to a value between zero and one. The curve is shown below. With a threshold of 0.5, values above the threshold are assigned class 1 and values below it class 0.

From a score to a probability
Write . The decision boundary is where . Taking gives the sigmoid curve above; the same threshold rule applies.
A typical score has the form . It can involve several variables and higher-order terms.
The loss function
The loss measures how well the prediction agrees with the label. It should be large for a confident wrong prediction and small for a confident correct one.
For a single observation, this gives
Here is the true label and is the predicted probability of class 1 for observation .
For computation, the average loss over the dataset can be written as one expression:
Fitting the model
Use gradient descent to minimise the loss and find the coefficients of the decision boundary.
Here indexes the parameter and the iteration. The update for parameter is
Each update starts from the previous estimate and takes a step against the gradient. The step size is controlled by . With a suitable step size the estimates approach the minimum.


