其他分享
首页 > 其他分享> > 吴裕雄--天生自然 人工智能机器学习实战代码:线性回归模型

吴裕雄--天生自然 人工智能机器学习实战代码:线性回归模型

作者:互联网

import numpy as np

from sklearn import datasets,linear_model
from sklearn.model_selection import train_test_split

def load_data():
    diabetes = datasets.load_diabetes()
    return train_test_split(diabetes.data,diabetes.target,test_size=0.25,random_state=0)

#线性回归模型
def test_LinearRegression(*data):
    X_train,X_test,y_train,y_test=data
    regr = linear_model.LinearRegression()
    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('Score: %.2f' % regr.score(X_test, y_test))

# 产生用于回归问题的数据集
X_train,X_test,y_train,y_test=load_data()
# 调用 test_LinearRegression
test_LinearRegression(X_train,X_test,y_train,y_test)

 

标签:人工智能,data,regr,test,train,LinearRegression,线性,吴裕雄,diabetes
来源: https://www.cnblogs.com/tszr/p/11177874.html