What is the purpose of positive parameter in sklearn.linear_model.ElasticNet?

I saw this parameter in the sklearn.linear_model.ElasticNet. What is the purpose of this? What is the possible scenario where we want to force the coefficients to be positive? How is this achieved? Doesn't it affect model performance?

positive : bool, default=False

When set to True, forces the coefficients to be positive.

Topic elastic-net regularization scikit-learn machine-learning

Category Data Science


The parameter constrains all coefficients to be positive. You as the model builder or a subject matter expert may have insight to believe that all coefficients should be positive in this model.

You can search for "positive" in here which is the coordinate descent code that handles the positive coefficient to see how this is achieved.

Usage may effect model performance - depending on how you define model performance for the problem. If the definition is inferencing - learning the coefficients for interpretation and business action where there is a belief that all effects are positive, then no this may not effect performance. There may be times that the real-world says the coefficients must be positive (e.g. miles per gallon or km per liter, number of tires on a car cannot be negative) but an artifact of the model fit may make these negative and invalid. If the problem says pure prediction performance (as measured by some metric of choice) then usage of this parameter may effect performance.

There is a class of models using constraints that help the modeler adjust the model to the problem. Here is one.

This comes down to the modeler knowing if using this functionality is relevant to the problem.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.