python - 如何决定 keras 密集层构造函数使用哪些参数?

标签 python machine-learning keras

我[显然]对此很陌生,并尝试使用 keras 进行多目标回归,使用 this作为我的向导,但我遇到了麻烦。我遇到麻烦的一件事是如何在 model.add(Dense(input_dim=4, output_dim=500)) 行中初始化 Dense 层。我认为 input_dim=4 是由于 XX_train 数组有 4 列,但我不确定。我也不清楚为什么 output_dim=500。 500的值(value)从何而来?是任意的吗?

我查看了keras文档here ,它使用 input_shape 参数,但我不确定应该为 unitsinput_shape 参数使用什么值。显然,仅需要为第一层传入 input_shape ,但对于所有后续层,units 参数应始终具有相同的值(链接中所示示例中的 32 )?该文档将单位定义为:“单位:正整数,输出空间的维数”,但我必须承认我不确定这意味着什么。这是否意味着如果我尝试预测 8 个特征的值(y_train、y_test),units=8

This指出我需要仅将 input_shape 传递到第一层,但它没有说明如何确定该形状。

我想要做什么:我有 11 列和数千行数据。我尝试使用其中 3 列作为特征来预测其他 8 列(已标记)。我可能错过了一些明显的东西,但有人能指出我正确的方向吗?据我所知,多目标回归甚至可能不是可行的方法。

感谢您的帮助。我为我明显的笨蛋道歉。如果我需要提供更多信息,请告诉我。

最佳答案

model.add(Dense(input_dim=4, output_dim=500)). I think the input_dim=4 is due to the XX_train array having 4 columns but am not sure

是的,这是正确的。 input_dim 为 4,因为 XX_train 有 4 列。

Where does the value of 500 come from? Is it arbitrary?

这是根据经验发现的。

Does it mean that if I'm trying to predict 8 features' values (y_train, y_test), units=8?

是的,这是正确的。

What I'm trying to do: I have 11 columns and thousands of rows of data. I'm trying to use 3 of those columns as features to predict to other 8 (which are labeled). I'm probably missing something obvious, but can someone point me in the right direction?

代码片段,只是作为起点。

from keras.layers import Dense, Activation
from keras.models import Sequential

model = Sequential()
model.add(Dense(32, activation='relu', input_dim=3))
model.add(Dense(64, activation='relu')) # add more layers as necessary
model.add(Dense(8))
model.summary()  # use summary() to verify model architecture

关于python - 如何决定 keras 密集层构造函数使用哪些参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56935032/

相关文章:

Python请求参数/处理api分页

python - 在 Keras 中同时增强 X,y

keras - 如何在 Keras 中实现分层 Transformer 进行文档分类?

tensorflow - 如何正确结合TensorFlow的Dataset API和Keras?

tensorflow - 在 Keras 分类神经网络中以精度换取更好的召回率

Python 2.7 - 使用多个字典的字符串替换

python - 我会遇到 python 的全局解释器锁的问题吗?

python - 以任意倍数删除数组中的项目

machine-learning - 互信息和预测准确性

python - 如何在keras中连接两层?