Created
November 9, 2017 01:49
-
-
Save 64lines/78aa515c8ba4960eb7ceb62157344091 to your computer and use it in GitHub Desktop.
[PYTHON][SKLEARN] Lasso Regression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Import Lasso | |
| from sklearn.linear_model import Lasso | |
| # Instantiate a lasso regressor: lasso | |
| lasso = Lasso(alpha=0.4, normalize=True) | |
| # Fit the regressor to the data | |
| lasso.fit(X, y) | |
| # Compute and print the coefficients | |
| lasso_coef = lasso.coef_ | |
| print(lasso_coef) | |
| # Plot the coefficients | |
| plt.plot(range(len(df_columns)), lasso_coef) | |
| plt.xticks(range(len(df_columns)), df_columns.values, rotation=60) | |
| plt.margins(0.02) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment