线性回归:boston房价

from sklearn.linear_model import LinearRegression,Lasso,Ridge
from sklearn.datasets import load_boston
import matplotlib.pyplot as plt

boston=load_boston()
data = boston.data
target = boston.target

x_train = data[:450]
y_train = target[:450]
x_test = data[450:]
y_test = target[450:]

lr = LinearRegression()
rr = Ridge()
lasso = Lasso()

lr.fit(x_train,y_train)
rr.fit(x_train,y_train)
lasso.fit(x_train,y_train)

y_lr = lr.predict(x_test)
y_rr = rr.predict(x_test)
y_lasso = lasso.predict(x_test)

plt.plot(y_test,label='real')
plt.plot(y_lr,label='lr')
plt.plot(y_rr,label='rr')
plt.plot(y_lasso,label='lasso')
plt.legend()
plt.show()

 

线性回归:boston房价


上一篇:python --- Boston房价 --- 一元线性回归


下一篇:前端生成32位uuid