0

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?

  • Maybe migrate to https://stats.stackexchange.com/ – MatthewR Jun 01 '19 at 20:01
  • `MLmetrics::MSE` is computing the ML estimator for the variance, not the bias. Just compare your `Variance` with `MSE`. You can see the code by running `MLmetrics::MSE`. – Rui Barradas Jun 01 '19 at 20:04

1 Answers1

0

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
  • The mse can be decomposed to MSE = Bias^2 + variance https://en.wikipedia.org/wiki/Bias%E2%80%93variance_tradeoff. So i trried to compute the mse by computing the components by hand – MasterStudent1992 Jun 01 '19 at 21:32
  • Link explains totally different concept. The MSE you want to calculate in your example is abreviation for mean squared error and the link shows a simple explanation: https://www.statisticshowto.datasciencecentral.com/mean-squared-error/ MSE function exactly computes this value. – Firat Bulut Jun 01 '19 at 22:18