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房价


相关文章:

  • 2021-12-08
  • 2022-01-07
  • 2022-01-07
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2021-07-08
  • 2021-12-21
猜你喜欢
  • 2021-09-13
  • 2022-01-09
  • 2021-12-24
  • 2021-12-09
  • 2021-09-14
  • 2021-06-20
相关资源
相似解决方案