I have two arrays.
I want a percent value that describes how much their values are different. I try using MSE and RMSE:
/**
* Mean Squared Error
* MSE = (1/n) * Ʃ[(r - p)^2]}
*/
export function computeMse(a, b) {
const size = a.length
let error = 0
for (let i = 0; i < size; i++) {
error += Math.pow(b[i] - a[i], 2)
}
return (1 / size) * error
}
/**
* Root Mean Squared Error
* RMSE = √MSE
*/
export function computeRmse(a, b) {
return Math.sqrt(computeMse(a, b))
}
and:
const a = [2354493, 2615706, 1594281, 1570894, 1930709, 2086681]
const b = [2354493, 2224360.55, 1906806.9, 1408769.93, 1609053.96, 2200698.72]
const mse = computeMse(a, b)
const rmse = computeRmse(a, b)
The result is:
mse: 65594986451.87959
rmse: 256115.18200192583
I don't think that this result is correct. First of all, mse and rmse are not in range [0, 100], and then are values very large even if the two array are not so different.
What I'm wrong?
I try also:
export function computeMape(actual, forecast) {
const size = actual.length
let error = 0
for (let i = 0; i < size; i++) {
error += Math.abs((actual[i] - forecast[i]) / actual[i])
}
return (100 * error) / size
}
with:
const a = [77, 50, 38, 30, 26, 18]
const b = [77, 81.13, 92.77, 101.98, 119.76, 121.26]
And I get mape: 230.10116059379217
...
Another example:
const a = [1.15, 1.09, 1.08, 0.78, 0.51, 0.44]
const b = [1.15, 1.61, 1.88, 2.13, 2.3, 2.47]
const mape = computeMape(a, b) // result: 184.53357461497413
Suppose you have this three dataset:
The red line rapresents the real data, the dotted green line rapresents the forecast data created by user (test 1) and the dotted gray line rapresents the forecast data created by user (test 2). In fact user can try different times to hit the real data (it's like a game).
Now I would like to return to the user a feedback telling the user how wrong he was to guess the trend of the data in terms of percentage.
The user can make numerous predictions. I would like a percentage number to tell me how much the user was wrong in order to compare each attempt.
Is it possible something like that?
Also in this case, I get NaN result:
const a = [132.6, 114.1, 134.5, 124.5, 144.4, 162.4]
const b = [132.6, 134.15, 134.15, 134.15, 139.19]
Why?