繁体   English   中英

如何为单个输入和多个 output 训练回归 model?

[英]How to train a Regression model for single input and multiple output?

I have trained a regression model that approximates the weights for the equation: Y = R+B+G For this, I provide pre-determined values of R, B and G and Y, as training data and after training the model, the model能够成功预测给定 R、B 和 G 值的 Y 值。我使用了一个具有 3 个输入的神经网络,1 个具有 2 个神经元的密集层(隐藏层)和具有单个神经元的 output 层(输出)。

    hidden = tf.keras.layers.Dense(units=2, input_shape=[3])
    output = tf.keras.layers.Dense(units=1)

但是,我需要实现与此相反的操作。 即,我需要训练一个 model,它接受 Y 的值并预测与 Y 的值相对应的 R、B 和 G 的值。我刚刚了解到回归完全是关于单个Z78E6221F6393D14CEDZF6393D1356666。 因此,我无法想到解决方案和解决方法。 请帮助。
(PS Is it possible to use the model that I have already trained, to do this? I mean, once, the weights have been determined for R, B and G, is it possible to manipulate the model to use these weights to map Y到 R、B 和 G?)

这是一个使用 tensorflow 中的神经网络开始解决问题的示例。

import numpy as np
from tensorflow.python.keras.layers import Input, Dense
from tensorflow.python.keras.models import Model

X=np.random.random(size=(100,1))
y=np.random.randint(0,100,size=(100,3)).astype(float)   #Regression

input1 = Input(shape=(1,))
l1 = Dense(10, activation='relu')(input1)
l2 = Dense(50, activation='relu')(l1)
l3 = Dense(50, activation='relu')(l2)
out = Dense(3)(l3)

model = Model(inputs=input1, outputs=[out])
model.compile(
    optimizer='adam',
    loss=['mean_squared_error']
    )

history = model.fit(X, [y], epochs=10, batch_size=64)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM