0

I have to arrays, one for predictions and another for true values.

Predictions:

array([[ 0.01365575,  0.01523909],
   [-0.00044139,  0.00269908],
   [ 0.03240077,  0.02496629],
   [ 0.03238605,  0.03045709],
   [ 0.03226778,  0.02878774],
   [ 0.03238199,  0.03221421]])

Real values:

array([[0.01212121, 0.01529052],
   [0.        , 0.0030581 ],
   [0.01818182, 0.01559633],
   [0.00757576, 0.007263  ],
   [0.00757576, 0.00382263],
   [0.00757576, 0.01070336]])

I am trying to calculate the std of the mae and rmse with the formula:

std_error = (1/n * sum(error_i- mean_error)^2)^1/2

So far I am trying to create an array with the mae and rmse values incrementally but with no success. I am implementing this:

for x in range(len(preds)):
    mae_std = (preds[:,0] - trues[['t1']])/x

for x in range(len(preds)):
    rmse_std = (((trues[['t2']] - preds[:,1])**2)/x)**1/2 

This way just takes forever and never really ends not sure why. I expected the results to be an array with the incremental values of the error and then I could try to use them on the std_error formula. What am I doing wrong? Is there a way to achieve what I describe faster?

1
  • you can index the arrays directly and compute the same? something like np.mean((preds[:,1] - trues[:,1])**2) (just an e.g) or you can use scikit learn metric submodule as well. scikit-learn.org/stable/modules/generated/… Commented May 27, 2021 at 9:33

1 Answer 1

1

Assuming your 2 arrays are modelizing (x,y) coordinates, you can compute the mse / mae as follows:

# compute MSE
mse = np.square(preds - real)
mse = np.sum(mse, axis = 1) / mse.shape[1]

# compute MAE
mae = np.sum(np.abs(preds - real), axis = 1) / mse.shape[1]

You can adapt your specific formula to match these...

Sign up to request clarification or add additional context in comments.

2 Comments

This return a number. Shouldn't it return an array of the error values for each sample? Because I then want to put them in error_i on the std_error formula.
if your initial pred & real arrays are of size (n, 2) then this returns an array of size (n, 1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.