我正在尝试在我的随机森林代码中测量 MAPE(平均绝对百分比误差)值。MAE 值为 7.5。当我尝试计算 MAPE 时,它输出:Accuracy: -inf %这是我计算 MAPE 的代码。如何使其工作或为什么不计算值。mape = 100 * (errors / test_labels)# Calculate and display accuracyaccuracy = 100 - np.mean(mape)print('Accuracy:', round(accuracy, 2), '%.')以下是值: errors: array([ 2.165, 6.398, 2.814, ..., 21.268, 8.746, 11.63 ]) test_labels: array([45, 47, 98, ..., 87, 47, 72])这些是类型:var1 int64var2 int64var3 float64var4 int64var6 float64var7 int64var1. float64dtype: object示例值,超过 8000 个条目 var1 var2. var3 var4 var5 var6 var7"420823370" "183" "2019-09-07 22:13:04" "84" "2019-09-07 22:12:46" "72" "00:00:18""420521201" "183" "2019-09-07 17:43:03" "84" "2019-09-07 17:42:51" "46" "00:00:12""420219554" "183" "2019-09-07 12:43:02" "88" "2019-09-07 12:42:39" "72" "00:00:23""419618820" "183" "2019-09-07 02:43:01" "92" "2019-09-07 02:42:46" "80" "00:00:15""419618819" "183" "2019-09-07 02:43:01" "84" "2019-09-07 02:42:46" "80" "00:00:15""417193989" "183" "2019-09-05 10:42:52" "82" "2019-09-05 10:42:23" "0" "00:00:29""416891691" "183" "2019-09-05 05:42:51" "78" "2019-09-05 05:42:49" "72" "00:00:02""416587222" "183" "2019-09-05 00:42:51" "88" "2019-09-05 00:42:35" "99" "00:00:16""416587223" "183" "2019-09-05 00:42:51" "82" "2019-09-05 00:42:35" "99" "00:00:16""416587224" "183" "2019-09-05 00:42:51" "80" "2019-09-05 00:42:35" "99" "00:00:16"id:Big Int. ts_tuid: Big Int. rssi: numeric. batl: real. ts_diff:interval
2 回答
绝地无双
TA贡献1946条经验 获得超4个赞
您收到此错误是因为当您的测试标签为 0 时 MAPE 未定义,这是使用 MAPE 的几个缺点之一。如果你替换accuracy = 100 - np.mean(mape)
为accuracy = 100 - np.mean(mape[np.isfinite(mape)])
你会得到一个更明智的数字。
手掌心
TA贡献1942条经验 获得超3个赞
本次输出以 mape 误差度量显示 Inf。其背后的原因是我们的观测值为零。当因变量可以将零作为输出之一时,我们不能使用 mape 作为误差度量。在这种情况下,应使用其他误差测量。
参考:https://rstudio-pubs-static.s3.amazonaws.com/390751_f6b763e827b24c9cb4406cd43129c8a9.html
添加回答
举报
0/150
提交
取消