线性回归-Rige回归
"""
回归模型1.2 Ridge regression
author :marco
"""
print (__doc__)
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets,linear_model,cross_validation
def load_data():
""" 加载数据"""
diabetes = datasets.load_diabetes()
return cross_validation.train_test_split(diabetes.data, diabetes.target, test_size=0.25, random_state=0)
def test_Ridge(*data):
X_train,X_test,y_train,y_test = data
regr = linear_model.Ridge(alpha=0.01)
regr.fit(X_train,y_train)
print("Coefficients :%s,intercept %.2f" %(regr.coef_,regr.intercept_))
print ("Residual sum of squares: %.2f" % np.mean((regr.predict(X_test)-y_test)**2))
print ('Sore: %.2f' % regr.score(X_test,y_test))
if __name__ =='__main__':
X_train,X_test,y_train,y_test = load_data()
test_Ridge( X_train,X_test,y_train,y_test)