Writing

Machine Learning (5) — Logistic Regression

Logistic regression and softmax for classification: sigmoid, cross-entropy loss, and gradient descent.

Preface: This covers classification problems. It follows the linear regression article because logistic regression follows nearly the same steps: write the objective, find the loss function, minimize it, solve for parameters, build the model, and evaluate. A classification algorithm and probability model that returns the probability of belonging to a class; cross-entropy loss; its derivative matches gradient descent. Softmax handles multi-class problems and improves accuracy.

Logistic Regression

  • Sigmoid function image image Loss function builds the model and outputs the probability of the target value to solve binary classification. image image A smaller loss maximizes probability, so take the logarithm of the loss first: image Then use differentiation to find the parameters that minimize the loss image image ## Softmax Regression Solves multi-class problems Write the probability function: image Note: Why use the exponential function? To show how small changes in data cause probability to grow exponentially.

  • Write the loss function image The first summation is over m samples; the second k sums all sample probabilities where y=j. Why use the logarithm? Because in the 0–1 range, the log changes rapidly.

  • Differentiate image

  • Gradient descent to solve for parameters image