簡體   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