sklearn.linear model.Lars

Jump to: navigation, search

A sklearn.linear model.Lars is an Least Angle Regression System within sklearn.linear_model class.

1) Import Lars Regression model from scikit-learn : from sklearn.linear_model import Lars
2) Create design matrix X and response vector Y
3) Create Lars Regression object: Larsreg=Lars([fit_intercept=True, verbose=False, normalize=True, precompute=’auto’, n_nonzero_coefs=500, eps=2.2204460492503131e-16, copy_X=True, fit_path=True, positive=False])
4) Choose method(s):
Input: Output:
#Importing modules
from sklearn.linear_model import Lars
from sklearn.model_selection import cross_val_predict
from sklearn.datasets import load_boston
from sklearn.metrics import explained_variance_score, mean_squared_error
import numpy as np
import pylab as pl
boston = load_boston() #Loading boston datasets
x = # Creating Regression Design Matrix
y = # Creating target dataset
Larsreg= Lars() # Create Lars regression object,y) # predicted values

#Calculaton of RMSE and Explained Variances

yp_cv = cross_val_predict(Larsreg, x, y, cv=10) #Calculation 10-Fold CV
RMSE =np.sqrt(mean_squared_error(y,yp))
RMSECV =sqrt(mean_squared_error(y,yp_cv)

# Printing Results

print('Method: Lars Regression')
print('RMSE on the dataset: %.4f' %RMSE)
print('RMSE on 10-fold CV: %.4f' %RMSECV)
print('Explained Variance Regression Score on the dataset: %.4f' %Evariance)
print('Explained Variance Regression 10-fold CV: %.4f' %Evariance_cv)

#plotting real vs predicted data

pl.plot(yp, y,'ro')
pl.plot(yp_cv, y,'bo', alpha=0.25, label='10-folds CV')
pl.title('Lars Regression')
lars boston10fold.png
(blue dots correspond to 10-Fold CV)

Method: Lars Regression
RMSE on the dataset: 4.6800
RMSE on 10-fold CV: 6.2862
Explained Variance Regression Score on the dataset: 0.7406
Explained Variance Regression 10-fold CV: 0.5320



Least Angle Regression model a.k.a. LAR.