Skip to content

Instantly share code, notes, and snippets.

@Ayushijain09
Created July 16, 2020 18:26
Show Gist options
  • Save Ayushijain09/47874871d18fddcebaebfb57299ccf61 to your computer and use it in GitHub Desktop.
Save Ayushijain09/47874871d18fddcebaebfb57299ccf61 to your computer and use it in GitHub Desktop.
LASSO Regression
from sklearn.linear_model import Lasso
from sklearn.model_selection import GridSearchCV
lasso= Lasso()
parameters = {'alpha':[1e-15, 1e-10, 1e-8, 1e-4,1e-3,1e-2,1,3,5]}
lasso_model = GridSearchCV(lasso, parameters, scoring = 'r2',cv=5)
lasso_model.fit(X_train,y_train)
pred = lasso_model.predict(X_test)
print(lasso_model.best_params_) #output {'alpha': 0.001}
print(lasso_model.best_score_) #output 0.8630550401365724
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment