In sklearn Lasso (link below):


, there is the coefficient 1/(2*n_samples) in the objective function: enter image description here

Why does Sklearn insert the coefficient there?


When minimizing squared error, you would often see $\tfrac{1}{2}$ there, because derivative of $\tfrac{1}{2} x^2$ is $x$, while for $x^2$ alone it's $2x$, so the first expression leads to more "elegant" formulation. As for n_samples, it is to make the loss function an average, so that it doesn't depend on sample size. Both are meant for humans to make reading the code and interpreting results easier, but doesn't matter from optimization point of view, since those are just constants. You can find nice explanation in this thread.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.