Logistic Regression
Logistic Regression
When Logistic Regression works as a Neural Network,


- Training: Fit the training data by getting the parameter $w_h$, $w_w$ and $w_0$
- Test: Run the trained formula from the inputs
Loss Function
Loss function is the function that we would like to minimize, it should be as small as possible
Mean squared error
One of the loss function is the Mean squared error (MSE), a.k.a. L2-norm, where $Y$ is the ground truth,
Cross-entropy loss
The commonly used loss function for logistic regression is Cross-entropy loss,
Note that the derivative of cross entropy loss,
Note that the Hessian matrix of the cross entropy loss,
which is a positive semi-definite (PSD) matrix, which means CE is a convex function and has a unique global minimum
Gradient Descent
Gradient Descent is used to figure out the (arguments) minimum of loss function

- Gradient Descent Algorithm:
- Initialize $w_h$, $w_w$ and $w_0$ (by random values, normal distribution, etc.)
- Calculate the output $Y^{\text{output}}$
- Update the weights (Iteration $i$):
- $\Delta w_i = \alpha_i \times 2(Y^{\text{output}} - Y)\frac{\partial Y^{\text{output}}}{\partial w_i}$
- $w_i = w_i - \Delta w_i$
- Repeat the steps 2 and 3 until it converges
Performance Evaluation
- Confusion Matrix:
Predicted class Actual class Positive Negative Positive True Positive (TP) False Negative (FN) Negative False Positive (FP) True Negative (TN)
Metrics
Accuracy
Among the predicted samples, how many of them are correctly predicted?Precision
Among the predicted positive samples, how many of them are correctly predicted?Recall
How many actual positive samples are predicted to be positive?F1-score
The weighted average of precision and recallBalanced accuracy
ROC Curve
- True Positive Rate (TPR): the ratio of recalled positives among all the positives
- False Positive Rate (FPR): the ratio of negatives predicted as positive

Area under ROC Curve

- Perfect classifier occurs when two distributions can be totally separated
- Random classifier occurs when two distributions are totally overlapped


