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

心已入冬 提交于 2019-12-23 17:55:44

问题


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?


回答1:


It seems that the

check_array

Returns one single object

See the documentation here



来源:https://stackoverflow.com/questions/45172561/scikit-learn-valueerror-not-enough-values-to-unpack-expected-2-got-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!