莫烦python教程学习笔记——线性回归模型的属性

# View more python learning tutorial on my Youtube and Youku channel!!!

# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
# Youku video tutorial: http://i.youku.com/pythontutorial

"""
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
"""
from __future__ import print_function
from sklearn import datasets
from sklearn.linear_model import LinearRegression

loaded_data = datasets.load_boston()
data_X = loaded_data.data
data_y = loaded_data.target

model = LinearRegression()
model.fit(data_X, data_y)

print(model.predict(data_X[:4, :]))
print(model.coef_)  #回归系数,即x的系数
print(model.intercept_)  #y轴截距,即常数值
print(model.get_params())  #模型参数,例如n_jobs等
print(model.score(data_X, data_y)) # R^2 coefficient of determination

猜你喜欢

转载自www.cnblogs.com/simpleDi/p/9963902.html