Reputation: 149
I tried to calculate the mse value for a test set by hand and by using the MSE function from the MLmetrics package but get different results.
Here is a reproducible example:
ActualValuesExample <- c(1,1,3,3,2,5,1)
MSE(PredictionExample,ActualValuesExample)
Bias <- mean(PredictionExample-ActualValuesExample)
Variance <- mean((PredictionExample-ActualValuesExample)^2)
# MSE = Bias^2 + Variance
(Bias)^2 + Variance
0.4489796 is the result for the computation by hand and 0.4285714 the result of the MSE function.
Where is my mistake, why i dotn get the same results?
Upvotes: 0
Views: 192
Reputation: 11
I don't understand why you add (Bias)^2 and Variance. MSE is simply equal to:
mean((PredictionExample-ActualValuesExample)^2) by definition. This is the variance variable in your example. More explicitly MSE is the mean of squred errors. Here error refers to (actual - predicted). I tried for an artifical value set and get the same results. Below is the code:
> ActualValuesExample <- c(1,1,3,3,2,5,1)
> PredictionExample <- c(3,1,2,4,3,2,2)
> MSE(PredictionExample,ActualValuesExample) == mean((PredictionExample-ActualValuesExample)^2)
[1] TRUE
Upvotes: 0