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