scikit-learn : ValueError: not enough values to unpack (expected 2, got 1)
scikit-learn : ValueError: not enough values to unpack (expected 2, got 1)
sklearn
的最新版本中有一个check_array
函数用于计算mean absolute percentage error (MAPE)
,但它的工作方式似乎与以前的版本不同。
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
Returns 一个对象
查看文档here
sklearn
的最新版本中有一个check_array
函数用于计算mean absolute percentage error (MAPE)
,但它的工作方式似乎与以前的版本不同。
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
Returns 一个对象
查看文档here