Languages
[Edit]
EN

JavaScript - Mean absolute error (MAE)

4 points
Created by:
mkrieger1
726

In this short article, we would like to show how to calculate Mean absolute error (MAE) using JavaScript.

MAE is kind of error formula that is useful in many cases.

Mean absolute error formula is:

Where:

  • n is the number of the samples,
  • y is expected sample values,
  • x is actual sample values.

 

Mean absolute error can be used in the cases where we are looking for approximated values - used for solved problems where it is not problem if once x(i) < y(i) and other time x(i) > y(i). That formula can be used in any modeling technique, e.g. Artificial Inteligence, Kriging, any approximation technique, etc.

 

Practical example

Edit

Let's suppose we have parabola function values: 0149 that were approximated by some technique giving: 0.10.93.510. The below source code shows how to calulate MAE for them.

 

Alternative solution

Edit

This solution is useful when we collect results during computation, and we don't want to create additional temporary array.

 

Resources

Edit
  1. Mean absolute error - Wikipedia
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join