在最近版本的 check_array 中有一个用于计算 mean absolute percentage error (MAPE)sklearn 函数,但它的工作方式似乎与以前的版本不同。

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)

这将返回错误: ValueError: not enough values to unpack (expected 2, got 1) 。这个错误有什么解决办法吗?

最佳答案

看来,

check_array

返回单个对象

请参阅文档 here

关于python - scikit-learn : ValueError: not enough values to unpack (expected 2, 得到 1),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45172561/

10-16 05:52