1
我在超市預測日常銷售額,並將其作爲損失函數使用體積加權mape。Tensorflow中的Wepe Mape
總和是在輸出節點。
我tensorflow實現這一點:
import tensorflow as tf
def weighted_mape_tf(y_true,y_pred):
tot = tf.reduce_sum(y_true)
wmape = tf.realdiv(tf.reduce_sum(tf.abs(tf.subtract(y_true,y_pred))),tot)*100
return(wmape)
不幸的是我的輸出是:
Epoch 4/800
0s - loss: 69.3939 - mean_squared_error: 819.6549 - mean_absolute_error: 14.0599
Epoch 5/800
0s - loss: 66.0676 - mean_squared_error: 768.5440 - mean_absolute_error: 13.4120
Epoch 6/800
0s - loss: 63.3000 - mean_squared_error: 728.7665 - mean_absolute_error: 12.8934
Epoch 7/800
0s - loss: 62.0189 - mean_squared_error: 704.7637 - mean_absolute_error: 12.5851
Epoch 8/800
0s - loss: 60.4229 - mean_squared_error: 682.0646 - mean_absolute_error: 12.2814
Epoch 9/800
0s - loss: 59.6329 - mean_squared_error: 674.8835 - mean_absolute_error: 12.1172
Epoch 10/800
0s - loss: 58.5069 - mean_squared_error: 656.2922 - mean_absolute_error: 11.9073
Epoch 11/800
0s - loss: 58.0447 - mean_squared_error: 643.9082 - mean_absolute_error: 11.7542
Epoch 12/800
0s - loss: 56.9352 - mean_squared_error: 628.5248 - mean_absolute_error: 11.5936
Epoch 13/800
0s - loss: 56.3520 - mean_squared_error: 620.7517 - mean_absolute_error: 11.4170
Epoch 14/800
0s - loss: 55.8395 - mean_squared_error: 610.4476 - mean_absolute_error: 11.2979
Epoch 15/800
0s - loss: inf - mean_squared_error: 611.3271 - mean_absolute_error: 11.2931
Epoch 16/800
0s - loss: nan - mean_squared_error: nan - mean_absolute_error: nan
Epoch 17/800
0s - loss: nan - mean_squared_error: nan - mean_absolute_error: nan
Epoch 18/800
0s - loss: nan - mean_squared_error: nan - mean_absolute_error: nan
Epoch 19/800
正如你看到的一段時間就變成始終NaN的後。 我猜錯誤是當tot == 0,但是當我插入一個簡單的if轉換 tot時,我仍然得到NaNs。
您對此問題有任何經驗嗎?
預先感謝您