损失:nan Keras回归 [英] loss: nan Keras regression
问题描述
我正在尝试预测一个连续值(第一次使用NN)。我已经标准化了输入数据。我不知道为什么从第一个纪元开始得到 loos:nan 输出。我阅读并尝试了以前对同一问题的回答中的许多建议,但没有一个对我有帮助。我的训练数据形状为:(201917,64)
I am trying to predict a continuous value (using NN for the first time). I have normalised the input data. I can't figure out why I am getting a loos:nan output starting with the first epoch. 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 正则化,更改批处理大小或将数据缩放到其他范围(例如 [-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.
这篇关于损失:nan Keras回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!