我已经做了线性回归和最佳拟合线,但也希望有一条线连接实际点(蓝色的)和预测点(红色的x)代表预测误差,或所谓的残差。情节应该以类似的方式呈现:
到现在为止我所拥有的是:
# draw the plot
xx=X[:,np.newaxis]
yy=y[:,np.newaxis]
slr=LinearRegression()
slr.fit(xx,yy)
y_pred=slr.predict(xx)
plt.scatter(xx,yy)
plt.plot(xx,y_pred,'r')
plt.plot(X,y_pred,'rx') #add the prediction points
plt.show()
提前非常感谢!在
下面是带有竖线的示例代码
相关问题 更多 >
编程相关推荐