加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

【线性回归】波士顿房价预测

发布时间:2020-12-14 04:44:19 所属栏目:百科 来源:网络整理
导读:from sklearn import datasets # 数据集 from sklearn.model_selection import train_test_split linear_model import matplotlib.pyplot as plt ? boston = datasets.load_boston() 波士顿房价数据 boston ? ? ? ? 创建训练集 与 测试集 x_train,x_test,y_t
from sklearn import datasets # 数据集
from sklearn.model_selection import train_test_split
 linear_model
import matplotlib.pyplot as plt 

?

boston = datasets.load_boston()  波士顿房价数据
boston

?

?

?

?

 创建训练集 与 测试集
x_train,x_test,y_train,y_test = train_test_split(boston.data,boston.target,test_size=0.1,random_state=42)
print(x_train.shape,x_test.shape,y_train.shape,y_test.shape)

?# 训练数据
?linreg = linear_model.LinearRegression()
?linreg.fit(x_train,y_train)

?

?# 得出预测值

?y_pred = linreg.predict(x_test)
?y_pred

?

?

?

?

?

plt.figure(figsize=(10,6))  设置大小

plt.plot(y_test,linewidth=3,label='Actual') 
plt.plot(y_pred,1)">Prediction)

 显示上面设置的名字与底部
plt.legend(loc=best)
plt.xlabel(test data point)
plt.ylabel(target value')

?


?


plt.plot(y_test,y_pred,'o')
plt.plot([-10,60],[-10,'k--')
plt.axis([-10,60,-10,60])


plt.xlabel('Actual')
plt.ylabel('Prediction')

?

?

?

?

?

?

?

有道词典
# 训练数据 linreg = ...
详细X
# training data Linreg = linear_model. LinearRegression () Linreg. Fit (x_train y_train)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读