Classification with a Logistic Unit
Logistic Regression as a Linear Classifier
A linear score followed by a sigmoid and trained with log loss is logistic regression, sometimes described as a single logistic neuron. It is not the classical perceptron, which uses a threshold decision rule and a different update algorithm.
Mathematical Formulation
For inputs , weights , and bias , the linear score is:
This equation represents the linear combination of inputs and their respective weights, with the bias term added to account for offsets. For classification, the sigmoid function, , is used as the activation function, transforming into a probability between 0 and 1:
This function outputs a value in the range , making it suitable for binary classification tasks.
Sigmoid Function
![]()
The sigmoid function, denoted as , plays a crucial role in machine learning, especially in logistic regression and neural networks, due to its ability to map any real-valued number into the interval. This property is particularly useful for modeling probabilities.
Definition
The sigmoid function is defined as:
where is the input to the function.
Properties
- Domain and Range: The function maps the domain of all real numbers to the range .
- Asymptotes: It has horizontal asymptotes at and , implying that approaches as and as .
- Symmetry: The identity makes the graph point-symmetric about , not about the origin.
- Sigmoid of Large Positive and Negative Values: For large positive values of , approaches , and for large negative values, approaches .
Derivative of the Sigmoid Function
The derivative of the sigmoid function is significant in machine learning algorithms, particularly in the optimization process. It can be computed using the chain rule of calculus and exhibits a simple form that is computationally efficient.
Calculation
Let's denote the derivative of with respect to as . The calculation proceeds as follows:
- Start with the definition .
- Applying the chain rule, we get:
- Simplifying, we obtain:
- By adding and subtracting in the numerator and rearranging, we find:
- Finally, recognizing that the terms in the parenthesis represent and respectively, we arrive at the elegant result:
Gradient Descent for Logistic Regression
Gradient descent is employed to minimize the error between the predicted and actual classifications. It adjusts the weights and bias to reduce the loss function, calculated using the log loss for classification:
where is the observed label and is the predicted probability from the sigmoid. A class label is obtained only after choosing a decision threshold. The loss function measures how well the predicted probability agrees with the observed label. The optimization's goal is to minimize by adjusting the model parameters, specifically the weights () and bias ().
To understand how changes in and affect , we calculate the partial derivatives of with respect to these parameters. This involves understanding how is influenced by and, in turn, how depends on each parameter.
Chain Rule Application
The calculation of and involves the application of the chain rule of calculus, expressed as:
The term is common across these expressions and is crucial for understanding the gradient's direction and magnitude.
Derivative Calculations
Derivative of with respect to
Given the log loss function, the derivative of with respect to is calculated as:
This expression represents how the loss function gradient depends on the difference between actual and predicted values.
Derivative of with respect to and
The predicted probability is the sigmoid of the linear score. The derivatives of with respect to , and are informed by the derivative of the sigmoid function:
Final Gradient Expressions
The final expressions for the partial derivatives of the loss function with respect to the parameters are:
These gradients guide the update steps in the gradient descent algorithm, indicating the direction and magnitude by which the parameters should be adjusted to reduce the loss.
Gradient Descent Update Rule
The gradient descent update rules for the weights and bias are as follows, where is the learning rate:
With an appropriate step size, these updates seek lower loss; finite parameter convergence also depends on the data, as the separable case below shows.
Conclusion
A linear score, sigmoid probability, and log loss form logistic regression. Gradient descent uses the compact gradients above to fit its weights. Keeping this terminology separate from the classical perceptron avoids mixing two related but distinct algorithms.
One update, and when no finite optimum exists
For , , and , the score is and the probability is . The gradient is . With , update all parameters together to ; then , , and the loss drops from to .
For multiple samples, average and at the current parameters before updating. Writing and including the intercept coordinate in , the loss Hessian is
Thus logistic regression with fixed features is convex in its parameters. Convexity alone does not guarantee a finite minimizer: on strictly linearly separable data, scaling a separating score sends every correct-class probability toward one and the loss toward zero, while weights diverge. A quadratic penalty on all parameters makes the objective coercive and strictly convex; in practice, whether the intercept is penalized must be specified. A small loss change can therefore indicate growing weights, not convergence to finite optimal parameters.
For threshold , predict class when ; the boundary is linear in the input features. Choose a different threshold when decision costs require it, rather than changing the derivative formulas. Evaluate the loss directly from logits with the stable expression in Log Loss; do not take logs of probabilities rounded to or .