回归模型与房价预测

1 from sklearn.datasets import load_boston
2 boston = load_boston()
3 boston.keys()

print(boston.DESCR)

 

 

boston.target
import pandas as pd
df = pd.DataFrame(boston.data)
df

from sklearn.linear_model import LinearRegression
LineR = LinearRegression()
LineR.fit(x.reshape(-1,1),y)
LineR.coef_
LineR.intercept_



import matplotlib.pyplot as plt
x=boston.data[:,5]
y=boston.target
plt.figure(figsize=(10,6))
plt.scatter(x,y)
plt.plot(x,9.1*x-34,'r')
plt.show()

 

import matplotlib.pyplot as plt
x = boston.data[:,12].reshape(-1,1)
y = boston.target
plt.figure(figsize=(10,6))
plt.scatter(x,y)

from sklearn.linear_model import LinearRegression
lineR=LinearRegression()
lineR.fit(x,y)
y_pred = lineR.predict(x)
plt.plot(x,y_pred)

plt.show()

from sklearn.preprocessing import PolynomialFeatures

poly = PolynomialFeatures(degree = 2)
x_poly = poly.fit_transform(x)

lrp = LinearRegression()
lrp.fit(x_poly,y)
y_poly_pred = lrp.predict(x_poly)
plt.scatter(x,y)
plt.scatter(x,y_pred)
plt.scatter(x,y_poly_pred)
plt.show()

 

转载于:https://www.cnblogs.com/fanfanfan/p/10075958.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值