0
$\begingroup$

I want to customize the loss vanilla loss function being used by scikit-learn classifiers like the Logistic Regression classifier, etc.

For example, if the vanilla empirical risk minimization formulation is as follows,

enter image description here

how can I change it to something like this?

enter image description here

Thanks.

$\endgroup$
1
  • $\begingroup$ LogisticRegression does support the L1 and L2 penalties, but otherwise I agree with @StefanPopov's answer that it's not generally possible. $\endgroup$
    – Ben Reiniger
    May 18 at 13:45

1 Answer 1

1
$\begingroup$

Looking at this GitHub issue I am afraid that's not possible.

In my experience working with the library, I have never worked on a use case that required such modification, I mostly change the values for the arguments in the constructor of the estimators.

I think that if you want to customise an algorithm (e.g., logistic regression) more, then you'd have to implement it yourself. On the other hand, I've found this StackOverflow question that specifies how you can implement a custom loss function for sklearn estimators, so maybe there's a workaround for it, even though it seems that the library was not designed to be used like that.

$\endgroup$
1
  • 1
    $\begingroup$ That SO question is about custom metrics (used for hyperparameter tuning e.g.), not the actual loss function being optimized by the model. $\endgroup$
    – Ben Reiniger
    May 18 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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