Desta Haileselassie Hagos
Desta Haileselassie Hagos

Reputation: 26206

scikit-learn : ValueError: not enough values to unpack (expected 2, got 1)

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?

Upvotes: 4

Views: 2164

Answers (1)

seralouk
seralouk

Reputation: 33182

It seems that the

check_array

Returns one single object

See the documentation here

Upvotes: 2

Related Questions