【发布时间】:2017-12-23 15:54:29
【问题描述】:
在最新版本的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)。这个错误有什么解决办法吗?
【问题讨论】:
-
那么你是怎么计算 MAPE 的?
-
检查下面答案中的链接。这回答了我的问题,希望对您也有帮助。
标签: python python-3.x scikit-learn sklearn-pandas