I have used linear_model.LogisticRegression
for a classification problem, with L1 regularization. My first tests were very satisfactory. However, my previous tests were done in R, using the glmnet package, and now I would like to understand why they differ.
I am trying to derive manually (by hand) the objective function minimized by linear_model.LogisticRegression
. According to the documentation, the function is $||w||_1 + C \sum_i \log(\exp(-y_i (X_i^T w + c)) + 1)$. However, I am failing to obtain this equation.
The starting point of my derivation is the negative log-likelihood, which I can work down into three derivations.
One derivation follows Andrew Ng's approach, which minimizes a function like $\sum y \log (p(x)) + (1-y_i) \log(1-p(x))$ (note that here $y\in\{0,1\}$). The second approach follows closely this lecture (http://www.stat.cmu.edu/~cshalizi/uADA/12/lectures/ch12.pdf , section 12.2.1), which results in a similar equation to the one used by scikit-learn, but not quite the same: $-\sum_i \log(1 + \exp(X_i^Tw+c)) + \sum_i y_i(X_i^Tw+c) + (\text{L1 term})$ (adapted to scikit-learn notation from equation 12.10). Close, but not cigar!
The third approach follows http://people.csail.mit.edu/jrennie/writing/lr.pdf, where $y\in\{1,-1\}$, like scikit-learn (internally), where the objective function is $-\sum_i \log(y_i g(X_i^Tw + c)) + (\text{L1 term})$, where $g(z) = \frac{1}{1+e^{-z}}$ is the logistic function (adapted from equation 7). Here, the objective function resembles scikit-learn's function, but the exponential term is inverted and the $y$ is not inside the exponential.
So the question is: what exactly is the L1 regularized logistic regression of scikit-learn minimizing ?
If it really is the likelihood, then my derivation is probably wrong at some point, is there a reference that explains the equation minimized according to the docs (and according to sklearn/svm/src/liblinear/linear.cpp
) ?
If it's not the likelihood, what is it, and where can I find more information?