RMSE for Multidimensional Data

Viewed 1281

For data that are one-dimensional or consist of a single column, calculating the error (RMSE) is simple. We can use python library, for instance

from sklearn.metrics import mean_squared_error
RMSE = mean_squared_error(y_actual, y_predicted, squared=TRUE)

Models can have multiple output columns 2, 10 or even 100..

How to calculate RMSE if the data has few columns?

For example:

y_act = np.array([1.022,0.94,1.278,2.096,1.404,
2.035,1.622,2.348,1.909,1.678, 
1.638,1.742,2.279,1.878,2.045] ) 
y_actual = y_act.reshape((5,3))
y_pred = np.array([1.021,0.84,1.111,2.091,1.314,
2.131,1.622,2.348,1.888,1.178, 
1.238,1.632,2.119,1.677,2.145] )
y_predicted = y_pred.reshape((5,3))

RMSE(y_actual - y_predicted)?

How the formula of the error changes?

1 Answers

The formula remains the same. How you use it will depend on your use case.

enter image description here

In your case you have 5 samples with 3 outputs(columns). Probably you ran some model on 3 different algorithms and got these results from them.

The difference from the 1D version is how you want to treat each output. You could do three things with it. In 1D version, you have just one value, here you have 3.

  1. Leave it as it is: In this case you have an MSE value each for all 3 outputs.
  2. Uniformly Average Them: Take the average of three MSE value you get to get one MSE value.
  3. Weighted Average: You can do a weighted average of the three MSE values.

These functionalities are available in the sklearn under the 'multi-output' parameter.

Here are examples to help you with manual computation v/s package computation

enter image description here

Related