线性回归:boston房价
Posted timlong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了线性回归: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房价的主要内容,如果未能解决你的问题,请参考以下文章