sklearn-5 LinearRegression预测房价


"""
@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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值