In order to get feature importance from a Lasso Regression in Python using Scikit-Learn, we need to follow these steps:
Here is an example code snippet that performs the above three steps:
main.py645 chars19 lines
The code first generates some toy input/output data. Then, a Lasso regression model is created with a chosen regularization parameter (alpha=0.1). The coefficients of the trained model are then retrieved using the lasso.coef_
command. Finally, the code sorts the coefficients based on their absolute value magnitude (greatest absolute value first) and prints out the feature index and its corresponding coefficient value.
gistlibby LogSnag