损失:执行回归时,Keras中的NaN [英] Loss: NaN in Keras while performing regression
问题描述
我正在尝试预测连续值(首次使用神经网络).我已经规范化了输入数据.我不知道为什么从第一个纪元开始就得到了loss: nan
输出.
I am trying to predict a continuous value (using a Neural Network for the first time). I have normalized the input data. I can't figure out why I am getting a loss: nan
output starting with the first epoch.
我阅读并尝试了以前对同一问题的回答中的许多建议,但没有一个对我有帮助.我的训练数据形状为:(201917, 64)
.
I read and tried many suggestions from previous answers to the same question but that none of them helped me. My training data shape is: (201917, 64)
.
这是我的代码:
model = Sequential()
model.add(Dense(100, input_dim=X.shape[1], activation='relu'))
model.add(Dense(100, activation='relu'))
model.add(Dense(100, activation='relu'))
# Output layer
model.add(Dense(1, activation='linear'))
# Construct the neural network inside of TensorFlow
model.compile(loss='mean_squared_error', optimizer='Adam')
# train the model
model.fit(X_train, y_train, epochs=10, batch_size=32,
shuffle=True, verbose=2)
推荐答案
简而言之,您可以按照以下步骤查找问题的原因:
In short, these are the steps that you can take to find the cause of your problem:
-
确保您的数据集应该是应该的:
Make sure that your dataset is what it should be:
- 在数据集中查找任何 nan / inf 并对其进行修复.
- 编码错误(将其转换为 UTF-8 ).
- 列或行中的值无效.
- Look for any nan/inf in your dataset and fix it.
- Incorrect encoding (convert it to UTF-8).
- Invalid values in your column or rows.
使用 Dropout , BatchNormalization , L1 / L2 正则化,更改您的 batch_size ,或将数据缩放到其他范围(例如 [-1,1] ).
Normalize your model using Dropout, BatchNormalization, L1/L2 regularization, change your batch_size, or scale your data to other ranges (e.g. [-1, 1]).
您可以检查此和
You can check this and this link to get extra help.
这篇关于损失:执行回归时,Keras中的NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!