【发布时间】:2023-11-23 18:34:01
【问题描述】:
我有一些来自线性函数 (y=mx+c) 的数据,其中 m=4, c=1 (so: y=4x+1)。
当我尝试使用 regress 取回系数时,我得到一个 R2m 值:
x = [1 2 3 4]
y = [5 9 13 17]
[m,bint,r,rint,stats] = regress(y',x');
%{
>> R = stats(1) % Coefficient of determination
R =
1
>> m % Linear function coefficients
m =
4.333333333333333
%}
而polyfit 这样做是正确的:
P = polyfit(x,y,1);
%{
>> P(1)
ans =
4.000000000000000
>> P(2)
ans =
1.000000000000000
%}
为什么会这样?
【问题讨论】:
标签: matlab linear-regression curve-fitting least-squares polynomials