Octave中求解算法多项式回归,最小二乘法的问题 [英] Problem in solving algorithm polynomial regression,least squares method in Octave
问题描述
我正在尝试使用最小二乘法实现多项式回归.绘制第三个图形时出现问题,未显示.我认为这是关于公式 y=ax+b 的实现.但就我而言,首先我使用内联函数 polyfit
和 polyval 获得了实验数据值.
I am trying to implement polynomial regression using the least squares method. There was a problem while plotting the 3rd graph, it is not displayed.
I think it's about the implementation of the formula y=ax+b.
But in my case, in first I got experimental data values using inline functions polyfit
and polyval.
x=0:0.1:5;
y=3*x+2;
y1=y+randn(size(y));
k=1;#Polynom
X1=0:0.01:10
B=polyfit(x,y1,k);
Y1=polyval(B,X1);
毕竟,我已经在使用线性模型用最小二乘法求解多项式回归了.
And after all, I am already using a linear model to solve the polynomial regression using the method of least squares.
Y2=Y1'*x+B'; -----this problem formula
subplot(3,2,3);
plot(x,Y1,'-b',X1,y1,'LineWidth');
title('y1=ax+b');
xlabel('x');
ylabel('y');
grid on;
结果,没有绘制图形.
推荐答案
检查向量的大小:x 和 Y1 的长度不同,X1 和 y1 的长度相同.
check size of the vector: x and Y1 are not same length, same for X1 and y1.
您可能想绘制为:
plot(x,y1,'-b',X1,Y1,'LineWidth', 1);
这篇关于Octave中求解算法多项式回归,最小二乘法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!