线性回归-Lasso回归
"""
auhtor:Marco
algorithm name :Lasso Regression
"""
print (__doc__)
import numpy as np
from sklearn import cross_validation,linear_model,datasets
def load_data():
diabets = datasets.load_diabetes()
return cross_validation.train_test_split(diabets.data,diabets.target,train_size=0.75,random_state=0)
def test_Lasso(*data):
X_train,X_test,y_train,y_test = data
regr = linear_model.Ridge(alpha=0.01)
regr.fit(X_train,y_train)
print('Coefficient %s,intercept %2.f' %(regr.coef_,regr.intercept_))
print('Residual sum of squares: %2.f' % np.mean((regr.predict(X_test)-y_test)**2))
print ('Score %2.f' % regr.score(X_test,y_test))
if __name__ =="__main__":
X_train, X_test, y_train, y_test = load_data()
test_Lasso(X_train,X_test,y_train,y_test)