4

There is a check_array function for calculating mean absolute percentage error (MAPE) in the recent version of sklearn but it doesn't seem to work the same way as the previous version.

import numpy as np
from sklearn.utils import check_array

def calculate_mape(y_true, y_pred): 
    y_true, y_pred = check_array(y_true, y_pred)

    return np.mean(np.abs((y_true - y_pred) / y_true)) * 100
y_true = [3, -0.5, 2, 7]; y_pred = [2.5, -0.3, 2, 8]
calculate_mape(y_true, y_pred)

This is returning an error: ValueError: not enough values to unpack (expected 2, got 1). Is there any fix for this error?

Desta Haileselassie Hagos
  • 23,140
  • 7
  • 48
  • 53

1 Answers1

2

It seems that the

check_array

Returns one single object

See the documentation here

seralouk
  • 30,938
  • 9
  • 118
  • 133