# sklearn.linear model.Lasso System

(Redirected from sklearn.linear model.Lasso)

A sklearn.linear_model.Lasso System is a linear least-squares L1-regularized regression system within sklearn.linear_model (that implements a LASSO algorithm to solve a LASSO task).

• Context:
• Usage:
1) Import Lasso Regression model from scikit-learn : `from sklearn.linear_model import Lasso`
2) Create design matrix `X` and response vector `Y`
3) Create Lasso Regression object: `lasso=Lasso(alpha=alpha[,fit_intercept=True, normalize=False,...])`
4) Choose method(s):
• Fit model with coordinate descent: ` lasso.fit(X, Y[, check_input]))`
• Predict Y using the linear model with estimated coefficients: `Y_pred = lasso.predict(X)`
• Return coefficient of determination (R^2) of the prediction: `lasso.score(X,Y[, sample_weight=w])`
• Compute elastic net path with coordinate descent: `lasso.path(X, y[, l1_ratio, eps, n_alphas,...])`
• Get estimator parameters: `lasso.get_params([deep])`
• Set estimator parameters: `lasso.set_params(**params)`
 Input: Output: from sklearn.cross_validation import KFold from sklearn.linear_model import Lasso from sklearn.datasets import load_boston boston = load_boston() x = np.array([np.concatenate((v,)) for v in boston.data]) y = boston.target lasso = Lasso(fit_intercept=True, alpha=0.5) lasso.fit(x,y) p = lasso.predict(x) plot(p, y,'ro') err = p-y total_error = np.dot(err,err) rmse_train = np.sqrt(total_error/len(p)) kf = KFold(len(x), n_folds=10) xval_err = 0 for train,test in kf: lasso.fit(x[train],y[train]) p = lasso.predict(x[test]) e = p-y[test] xval_err += np.dot(e,e) rmse_10cv = np.sqrt(xval_err/len(x)) Method: Lasso Regression RMSE on training set: 4.9141 RMSE on 10-fold CV: 5.7368