Keras with TensorFlow:...总是有损失:当一个输入列全为零时为nan

时间:2017-09-27 19:33:52

标签: python-3.x tensorflow deep-learning keras

我正在使用tensorflow==1.2.1Keras==2.0.6来构建模型:

input_num = X_norm_keras[:,2:].shape[1]
model_keras = Sequential()
model_keras.add(Dense(5, input_dim=input_num, activation='relu',kernel_regularizer=regularizers.l2(0.2)))
model_keras.add(Dense(1, activation='linear',kernel_regularizer=regularizers.l2(0.2)))

model_keras.compile(loss='mean_squared_error',  optimizer='adam')
model_keras.fit(X_norm_train[:,2:], y_norm_train, batch_size=20, epochs=10)

但得到以下输出:

Epoch 1/10
20/20 [==============================] - 0s - loss: nan
Epoch 2/10
20/20 [==============================] - 0s - loss: nan
Epoch 3/10
20/20 [==============================] - 0s - loss: nan
Epoch 4/10
20/20 [==============================] - 0s - loss: nan
Epoch 5/10
20/20 [==============================] - 0s - loss: nan
Epoch 6/10
20/20 [==============================] - 0s - loss: nan
Epoch 7/10
20/20 [==============================] - 0s - loss: nan
Epoch 8/10
20/20 [==============================] - 0s - loss: nan
Epoch 9/10
20/20 [==============================] - 0s - loss: nan
Epoch 10/10
20/20 [==============================] - 0s - loss: nan

更新

我发现原因是由于一个输入列全部为零。但是,我想知道为什么这会成为TensorFlow中的一个问题?在现实生活中,训练集中的输入特征之一可能在期望的时间段内全为零。此外,其他算法,如随机森林或岭回归处理这种情况很好。为什么TensorFlow会在这种情况下失败?

0 个答案:

没有答案