MATLAB-1: 线性拟合(r2、系数和系数误差)

输出

f = 

     Linear model Poly1:
     f(x) = p1*x + p2
     Coefficients (with 95% confidence bounds):
       p1 =      -3.036  (-3.201, -2.871)
       p2 =        10.9  (8.967, 12.83)

r2 =

    0.9873


coeff =

   -3.0361   10.8993


confid =

   -3.2013    8.9671
   -2.8708   12.8315

>> g

g = 

           sse: 91.2308
       rsquare: 0.9873
           dfe: 19
    adjrsquare: 0.9866
          rmse: 2.1913

代码

clear
close 
clc

x = 0:20;
y = -3*x+10+2*randn(size(x));
figure
plot(x,y,'o');
hold on

[f,g,o] = fit(x',y','poly1');
y_fit = f(x);
plot(x,y_fit,'-');
hold on;

f
r2=g.rsquare %r2的值
coeff=coeffvalues(f) % 拟合系数
confid=confint(f) % 误差

你可能感兴趣的:(编程,经验分享)