• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ahmetcecen/MultiPolyRegress-MatlabCentral: Multivariate Polynomial Regression

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

ahmetcecen/MultiPolyRegress-MatlabCentral

开源软件地址(OpenSource Url):

https://github.com/ahmetcecen/MultiPolyRegress-MatlabCentral

开源编程语言(OpenSource Language):

MATLAB 100.0%

开源软件介绍(OpenSource Introduction):

View Multivariate Polynomial Regression on File Exchange

Example For MultiPolyRegress

X is your Data matrix. 500 data point with 5 dimensions. Another way to look at this is 500 samples of 5 independent variables. Y is your observation vector 500 by 1. You want to find a good polynomial fit of columns of X to Y. Lets say you decided fit a 2nd degree polynomial to all 5 independent variables. And you are for the moment, interested in fitting the standard polynomial basis without further meddling with the terms.

Contents

How to Use the Inputs

Plain

load Example.mat
reg=MultiPolyRegress(X,Y,2) % Gives you your fit.
reg = 
       FitParameters: '-----------------'
         PowerMatrix: [21x5 double]
              Scores: [500x21 double]
PolynomialExpression: [21x2 table]
        Coefficients: [21x1 double]
                yhat: [500x1 double]
           Residuals: [500x1 double]
       GoodnessOfFit: '-----------------'
             RSquare: 0.9392
                 MAE: 0.0334
              MAESTD: 0.0481
       Normalization: '1-to-1 (Default)'
  LOOCVGoodnessOfFit: '-----------------'
           CVRSquare: 0.9280
               CVMAE: 0.0366
            CVMAESTD: 0.0590
     CVNormalization: '1-to-1 (Default)'

Normalization - Range

Different error definition ONLY in the calculation of MAE, MAESTD, CVMAE and CVMAESTD. Does not effect the fit.

reg=MultiPolyRegress(X,Y,2,'range')
reg =

       FitParameters: '-----------------'
         PowerMatrix: [21x5 double]
              Scores: [500x21 double]
PolynomialExpression: [21x2 table]
        Coefficients: [21x1 double]
                yhat: [500x1 double]
           Residuals: [500x1 double]
       GoodnessOfFit: '-----------------'
             RSquare: 0.9392
                 MAE: 0.0293
              MAESTD: 0.0313
       Normalization: 'Range'
  LOOCVGoodnessOfFit: '-----------------'
           CVRSquare: 0.9280
               CVMAE: 0.0313
            CVMAESTD: 0.0346
     CVNormalization: 'Range'

Figure

You would like to see a scatter plot of your fit.

reg=MultiPolyRegress(X,Y,2,'figure');

PV

You would like to limit the observed powers of certain terms in your polynomial. For example, you do not want the 1st and 4th Independent Variables (x1 and x4) to have second order terms (x1^2 or x4^2). Notice you have to explicitly write how high each term can go in powers, so I would also state I am fine with (x2 x3 and x5) having 2nd order terms.

reg=MultiPolyRegress(X,Y,2,[1 2 2 1 2]);
PolynomialFormula=reg.PolynomialExpression
PolynomialFormula =

Coefficient     Term  
___________    _______

  0.0022642    'x5'   
  0.0058919    'x4'   
-0.00049119    'x4.x5'
    0.01644    'x3'   
-0.00098813    'x3.x5'
 7.6129e-05    'x3.x4'
   0.014969    'x2'   
 -0.0023337    'x2.x5'
  0.0028077    'x2.x4'
-0.00012646    'x2.x3'
  -0.027613    'x1'   
-0.00036617    'x1.x5'
-0.00043459    'x1.x4'
-0.00011518    'x1.x3'
 -0.0009348    'x1.x2'
     3.9964    ''     
  0.0004941    'x2^2' 
 0.00014775    'x3^2' 
   0.010017    'x5^2' 

How to Use the Outputs

reg=MultiPolyRegress(X,Y,2);

PowerMatrix

You have a new data point you would like to evaluate using the computed fit. Lets assume for the sake of argument that the 250th row of X is in fact a new data point.

Unless you have a stake in deeply understanding this code, don't try to make sense of the NewScores matrix, or what follows. I sometimes have to stare at it for a couple minutes to figure it out myself. I am happy discuss this in detail upon specific request.

You have to repeat this procedure for every new data point. It might be time saving to write a function that does this automatically, however I never needed this functionality, so I wouldn't count on me writing that.

NewDataPoint=X(250,:);
NewScores=repmat(NewDataPoint,[length(reg.PowerMatrix) 1]).^reg.PowerMatrix;
EvalScores=ones(length(reg.PowerMatrix),1);
for ii=1:size(reg.PowerMatrix,2)
EvalScores=EvalScores.*NewScores(:,ii);
end
yhatNew=reg.Coefficients'*EvalScores % The estimate for the new data point.
yhatNew =

5.2877

Scores

Unless you have a stake in deeply understanding this code, don't try to make sense of the Scores matrix, chances are you won't ever need to use it.

Polynomial Expression

You would like to see the actual formula of the fit,

PolynomialFormula=reg.PolynomialExpression
PolynomialFormula =

Coefficient     Term  
___________    _______

  0.0052679    'x5'   
  0.0073888    'x4'   
-8.7941e-05    'x4.x5'
   0.016723    'x3'   
-0.00097694    'x3.x5'
 8.3902e-05    'x3.x4'
   0.015417    'x2'   
 -0.0025415    'x2.x5'
   0.002392    'x2.x4'
-0.00018939    'x2.x3'
  -0.028576    'x1'   
-0.00045571    'x1.x5'
-0.00037732    'x1.x4'
-0.00010521    'x1.x3'
-0.00047654    'x1.x2'
     4.0108    ''     
-4.9811e-05    'x1^2' 
-0.00026949    'x2^2' 
 0.00014575    'x3^2' 
-6.5765e-05    'x4^2' 
   0.011599    'x5^2' 

Cofficients

This was shown earlier at the input examples.

Legend

This was shown earlier at the input examples.

yhat

This is the vector of estimates using your new fit. The scatter plot you see when you use the 'figure' option is generated using scatter(yhat,y).

Residuals

This is defined as y-yhat. Can be used for a residual plot to see if ordinary least squares assumptions hold true.

Goodness of Fit Measures

These are useful not only in assesing the accuracy of your fit, but also comparing different candidates. For example, lets see how different powers compare for the same fit for the above dataset. I personally would like to use CVMAE as my comparative error measure, since it is more sensitive to overfitting.

It turns out, the second degree polynomial is the best option. One way to interpret this number is saying the fit makes in average a 3.66% error with respect to the original Y when estimating.

for ii=1:5
reg=MultiPolyRegress(X,Y,ii);
CVMAE(ii)=reg.CVMAE;
end
CVMAE
CVMAE =

0.0383    0.0366    0.0416    0.1255    3.7904


Published with MATLAB® R2014b




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
osqp/osqp-matlab: Matlab interface for OSQP发布时间:2022-08-17
下一篇:
optimizers/logging4matlab: Simple Logging Module for Matlab发布时间:2022-08-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap