MATLAB|曲线拟合基本介绍

2018-02-06  本文已影响1082人  冰冻生菜ch

曲线拟合工具箱cftool基本介绍

Tips

mathworks官网的和help文件
https://cn.mathworks.com/help/curvefit/fit-comparison-in-curve-fitting-app.html
在mathworks官网找到相应的help文件,点击右上角的Translate This Page,可以查看中文翻译,虽然是自动翻译的,很不准确,但偶尔可以看看。

☆曲线拟合工具箱界面


☆☆操作方法

☆☆☆如何选取最好的拟合结果

To determine the best fit, you should examine both the graphical and numerical fit results.

第一步:查看图的拟合结果【Examine the Graphical Fit Results】
第二步:检查数值结果【Evaluate the Numerical Fit Results】

SSE【the sum of squares due to error】:误差平方和
R-square: 复相关系数或复测定系数
Adjusted R-square:调整自由度的复相关系数
RMSE【Root mean squared error】: 均方根误差

The adjusted R-square statistic is generally the best indicator of the fit quality when you add additional coefficients to your model.

当SSE和RMSE越小,R越接近于1时标明拟合的越好。

☆☆☆☆其他操作

MATLAB help文件里有有个Note:
The fitted coefficients associated with the constant, linear, and quadratic terms are nearly identical for each normalized polynomial equation. However, as the polynomial degree increases, the coefficient bounds associated with the higher degree terms cross zero, which suggests overfitting.
对于多项式拟合,多项式阶数越高,如果拟合系数的置信区间接近0,说明可能过度拟合了。。。

MATLAB中的fit函数

options =
 
        Normalize: 'off'
          Exclude: []
          Weights: []
           Method: 'NonlinearLeastSquares'
           Robust: 'Off'
       StartPoint: [1x0 double]
            Lower: [0 -Inf 0 0 -Inf 0]
            Upper: [1x0 double]
        Algorithm: 'Trust-Region'
    DiffMinChange: 1.0000e-08
    DiffMaxChange: 0.1000
          Display: 'Notify'
      MaxFunEvals: 600
          MaxIter: 400
           TolFun: 1.0000e-06
             TolX: 1.0000e-06

Normalize: 对数据归一化处理
Exclude: 排除数据
Weights: 加权
Method: 拟合方法, 非线性最小二乘法
Robust: 稳健方式(通过加权方式排除异常值影响)
StartPoint: 拟合开始点
Lower: 拟合参数下界
Upper: 拟合参数上界
Algorithm: 算法 '置信区间'
DiffMinChange: 差分时参数最小变化值
DiffMaxChange: 差分时参数最大变化值
Display: 显示通知
MaxFunEvals: 最大函数计算次数
MaxIter: 最大迭代次数
TolFun: 函数精度
TolX: 参数精度

MATLAB线性拟合函数polyfit、polyval、polyconf

  1. 多项式拟合与线性回归分析对比案例,polyfit、polyval、polyconf
  2. MATLAB 线性拟合小结 —— polyfit
% 原始数据
data1; %x数据
data2; %y数据
% cftool查看
cftool(data1,data2);
% 多项式拟合
[pp1,ss1]=polyfit(data1,data2,1),%%一次多项式
nh_line=polyval(pp1,data1);%拟合曲线,相当于:nh_line=pp1(1,1).*data1+pp1(1,2);
% 得到具有75%保证率的直线
[yhat,delta]=polyconf(pp1,data1,ss1,0.25); %% 0.25表示1-0.25保证率
pp75=polyfit(data1,yhat+delta,1); %%公式
% 绘图
figure;
plot(data1,data2,'ko');hold on; %原始数据
plot(data1,nh_line,'b-','LineWidth',2.5);% 拟合的一次曲线
plot(data1,yhat+delta,'r:','LineWidth',2.5);% 具有75%保证率的直线--上限
plot(data1,yhat-delta,'r:','LineWidth',2.5);% 具有75%保证率的直线--下限

推荐阅读:

上一篇 下一篇

猜你喜欢

热点阅读