在最近的sklearn
版本中,有一个用于计算平均绝对百分比误差(MAPE)的check_array
函数,但它似乎与以前的版本不同。
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)
。这个错误有什么解决方法吗?