绘图最小二乘法
Plot least squares method
所以这是我使用最小二乘法绘制的回归线的八度图。
有没有办法添加像小箭头或线一样将点与实际线连接起来?这是我希望它看起来像的示例。谢谢
我认为没有用于绘制残差的特定函数,但手动绘制相当简单:
% 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], 'linewidth', 1.5 )
% Plot residual lines
plot( [xpoints;xpoints], [model(xpoints);ypoints], 'k:', 'linewidth', 1.5 )
hold off;
所以这是我使用最小二乘法绘制的回归线的八度图。
有没有办法添加像小箭头或线一样将点与实际线连接起来?这是我希望它看起来像的示例。谢谢
我认为没有用于绘制残差的特定函数,但手动绘制相当简单:
% 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], 'linewidth', 1.5 )
% Plot residual lines
plot( [xpoints;xpoints], [model(xpoints);ypoints], 'k:', 'linewidth', 1.5 )
hold off;