Code covered by the BSD License  

Highlights from
Error related performance metrics

5.0

5.0 | 6 ratings Rate this file 25 Downloads (last 30 days) File Size: 2.66 KB File ID: #15130

Error related performance metrics

by Skynet

 

28 May 2007 (Updated 04 Jul 2007)

Determine various error related performance metrics.

| Watch this File

File Information
Description

errperf(T,P,M) uses T and P, which are target and prediction vectors respectively, and returns the value for M, which is one of several error related performance metrics.

T and P can be row or column vectors of the same size. M can be one of the following performance metrics:
 
mae (mean absolute error)
mse (mean squared error)
rmse (root mean squared error)

mare (mean absolute relative error)
msre (mean squared relative error)
rmsre (root mean squared relative error)

mape (mean absolute percentage error)
mspe (mean squared percentage error)
rmspe (root mean squared percentage error)
 
EXAMPLE:
 
rand('state',0)
T = [0:0.2:1];
P = rand(size(T)).*T;
errperf(T,P,'mae') returns 0.1574
 
To compute the relevant performance metric, the function uses recursion to first compute one or more error vectors. The function can therefore secondarily be used to compute these error vectors. M can therefore also be one of the following:

e (errors)
ae (absolute errors)
se (squared errors)

re (relative errors)
are (absolute relative errors)
sre (squared relative errors)

pe (percentage errors)
ape (absolute percentage errors)
spe (squared percentage errors)

REMARKS:

The Neural Network Toolbox also has functions to compute mae and mse. This function does not make use of the toolbox.

Percentage error equals relative error times 100.

The abbreviations used in the code, and the calculation tree are documented in a comments section within the file.

[Please subscribe to this file if you use it, so you can be notified of updates.]

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
machine learning, metric, perf, performance, performance measure, probability, statistics
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
31 May 2011 Mehdi Moghaddam

thanks... u saved my time:)

26 May 2010 Biljana

Thanks for posting the file. It is what I need.

08 Apr 2009 Arturo Ayala  
16 Jun 2008 Clare Jeffers

It does what it says. Thanks for posting this.

06 Jun 2007 Amit Belani

Dimitri, using an input parser, and using assert, are of course standard and recommended programming practices. I hope you can upgrade to R2007a.

In writing the code, I've chosen a separation of concerns approach that in this case does not produce the most optimal or short code, but it does make understanding the code easier for me, and hopefully for others too. Additionally, this approach also allows for the extraction of various error vectors, as documented in the description.

05 Jun 2007 Dimitri Shvorob

'Written with R2007a' does not mean 'will work only with R2007a'; for the record, my 'much older' release is 2005's Matlab 7.0.4. If you want to include in your code elements that don't add much/any functionality, but do add problems to a majority of FEX audience, it's your right. You are also correct that 6 one/two-liners are not going to take 1-2 lines overall. Let's say they will take 12 lines; your code takes a hundred. 'Disparaging comments' are my private opinion; I am sure that your code will find many appreciative users.

04 Jun 2007 Amit Belani

Dimitri, you're obviously using a much older version of MATLAB - one which does not come with inputParser. It is clearly stated here and also within the file itself that this function was written with R2007a. Nonetheless, you can comment out the entire "Parse and validate input" section, and as long as your inputs are right, the code should still work.

It is true that each of the advertised metrics can be be calculated in one to two lines each, but obviously all of them cannot be calculated in two lines total.

I suggest looking at code much more carefully before posting disparaging comments.

04 Jun 2007 Dimitri Shvorob

Actually, referring to the provided example,
errperf(T,P,'mae')
returns
??? Undefined function or variable 'inputParser'.
Now, each of the metrics on offer can be coded in 1-2 lines - why does your code take a hundred?

01 Jun 2007 Melek Yalcintas  
Updates
07 Jun 2007

(1) Added support for metrics MARE, MSRE, and RMSRE.
(2) Addressed a possible division by zero condition in calculating relative and percentage errors.

04 Jul 2007

Added MATLAB version check.

Contact us