您的位置:首页 > 其它

sklearn-5 LinearRegression预测房价

2018-01-05 16:13 176 查看
"""
@author: Vincnet_Sheng
@file: Scikit_learn(sklearn)-5.py
@time: 2018/1/4 0004 下午 1:56
#-*- coding: utf-8 -*
"""

# topic: 1) use linearRegression to predict the house sale of Boston
#        2) viz the data with scatter plot

from sklearn import datasets
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

# input data from datasets.load_boston
loaded_data = datasets.load_boston()
data_X = loaded_data.data
data_y = loaded_data.target

# training with LinearRegression
model = LinearRegression()
model.fit(data_X, data_y)

# check the difference between prediction and reality
print(model.predict(data_X[:4,:]))
print(data_y[:4])

#制造线性回归的x,y点,100个例子,特征1,target=1, noise=10
X, y =datasets.make_regression(n_samples=100, n_features=1, n_targets=1, noise=10)
plt.scatter(X, y)     #散点图形式呈现
plt.show()  #输出呈现

输出:

[ 30.00821269  25.0298606   30.5702317   28.60814055]  #prediction

[ 24.   21.6  34.7  33.4]   #reality target

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: