Elastic net regression or lasso regression with weighted samples (sklearn)

Viewed 3342

Scikit-learn allows sample weights to be provided to linear, logistic, and ridge regressions (among others), but not to elastic net or lasso regressions. By sample weights, I mean each element of the input to fit on (and the corresponding output) is of varying importance, and should have an effect on the estimated coefficients proportional to its weight.

Is there a way I can manipulate my data before passing it to ElasticNet.fit() to incorporate my sample weights?

If not, is there a fundamental reason it is not possible?

Thanks!

1 Answers

You can read some discussion about this in sklearn's issue-tracker.

It basically reads like:

  • not that hard to do (theory-wise)
  • pain keeping all the basic sklearn'APIs and supporting all possible cases (dense vs. sparse)

As you can see in this thread and the linked one about adaptive lasso, there is not much activity there (probably because not many people care and the related paper is not popular enough; but that's only a guess).

Depending on your exact task (size? sparseness?), you could build your own optimizer quite easily based on scipy.optimize, supporting this kind of sample-weights (which will be a bit slower, but robust and precise)!

Related