我有一个回归问题,我必须从提供的数据中预测 3 个数值。例如,假设我有一个包含X1,X2,X3,X4,X5,X6...X100,Y1,Y2,Y3
列的数据集。在这种情况下,我必须预测Y1,Y2,Y3
值。有什么方法可以使用Keras构建模型以同时获得所有输出。
从 Keras 获取多个输出
数据挖掘
机器学习
Python
神经网络
喀拉斯
回归
2021-09-29 00:48:40
2个回答
很容易做!需要注意的一件事是我使用的是 Keras 功能 API。
from keras.layers import Input, Dense
Input_1= Input(shape=(shape, ))
x = Dense(100, activation='relu')(Input_1)
x = Dense(100, activation='relu')(x)
x = Dense(100, activation='relu')(x)
out1 = Dense(1, activation='linear')(x)
out2 = Dense(1, activation='linear')(x)
out3 = Dense(1, activation='linear')(x)
model = Model(inputs=Input_1, outputs=[out1,out2,out3])
model.compile(optimizer = "rmsprop", loss = 'mse')
您可以将输出层设置为具有 3 个节点。训练时,将输出设置为包含.
model.add(Dense(3, activation='linear'))
上面没有提到我们有一个线性回归,也添加密集层会让模型采取不同的同时在开始时,我仍然更喜欢 keras 的 \textbf{Model} Api,作为多输出模型