gpt4 book ai didi

python - 损失 : NaN in Keras while performing regression

转载 作者:行者123 更新时间:2023-12-04 12:25:39 27 4
gpt4 key购买 nike

我正在尝试预测一个连续值(第一次使用神经网络)。我已经标准化了输入数据。我不明白为什么我会收到 loss: nan从第一个纪元开始的输出。
我阅读并尝试了以前对同一问题的回答中的许多建议,但没有一个对我有帮助。我的训练数据形状是:(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)

最佳答案

您可以采取以下步骤来找出问题的原因:

  • 确保您的数据集是它应该的样子:
  • 寻找任何 /信息 在您的数据集中并修复它。
  • 编码不正确(将其转换为 UTF-8 )。
  • 列或行中的值无效。

  • 使用 规范化您的模型辍学 , 批量归一化 , L1 / L2 正则化 ,换你的批量大小 ,或将您的数据缩放到其他范围(例如 [-1, 1] )。
  • 减小网络的大小。
  • 更改其他超参数(例如 优化器 激活函数 )。

  • 您可以查看 thisthis获得额外帮助的链接。

    关于python - 损失 : NaN in Keras while performing regression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53640858/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com