如何解决绘制最小二乘法
有没有办法添加像连接点和实际线的小箭头或线?这是我希望它看起来像的一个例子。谢谢
解决方法
我不认为有用于绘制残差的特定函数,但手动执行此操作相当简单:
% Let's assume this is our model,predicting y from x
model = @sin;
% Define the x domain,which will be used for plotting
xdomain = 0:0.1:10;
% Define some (x,y) input points
xpoints = 10 * rand(1,10);
ypoints = model(xpoints) + 0.5 * randn(size(xpoints));
% Plot model
plot( xdomain,model(xdomain),'k-','linewidth',1.5 );
hold on;
% Plot input points
plot( xpoints,ypoints,'ko','markersize',8,'markeredgecolor','k','markerfacecolor',[0.4,0.4,0.4],1.5 )
% Plot residual lines
plot( [xpoints;xpoints],[model(xpoints);ypoints],'k:',1.5 )
hold off;
![](https://i.stack.imgur.com/kpyVW.png)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。