神经网络–预测多个变量的值 [英] Neural Network – Predicting Values of Multiple Variables

查看:260
本文介绍了神经网络–预测多个变量的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据,其中A,B,C列为输入,D,E,F,G列为输出.桌子的形状为(1000,7).我想训练模型,验证并测试它.

I have data with columns A, B, C as inputs and columns D, E, F, G as outputs. The table has a shape (1000,7). I would like to train the model, validate and test it.

我的数据:

My data:

A = [100, 120, 140, 160, 180, 200, 220, 240, 260, 280];
B = [300, 320, 340, 360, 380, 400, 420, 440, 460, 480];
C = [500, 520, 540, 560, 580, 600, 620, 640, 660, 680]; 

我想要的结果:

My desired outcome:

对于A,B,C的每个组合->我得到D,E,F,G作为输出(例如):

For each combination of A, B, C --> I get D, E, F, G as outputs (for example):

D = 2.846485609 
E = 5.06656901
F = 3.255358183
G = 5.464482379)

此外,对于A,B,C的每个不同组合;我有一组不同的输出(D,E,F,G).

Also, for each different combination of A, B, C; I have a different set of outputs (D, E, F, G).

我的问题: 是否有可能训练一个神经网络,使用这个经验丰富的网络来预测D,E,F,G的新值; A,B,C的新组合?

My Question: Is it possible to train a neural network, using this experienced network to predict new values of D, E, F, G; for new combination of A, B, C?

推荐答案

由于输出是连续值,因此该问题属于多元回归"类别.因此,您可以训练具有4个输出节点和大小为4的输入特征向量的神经网络(NN).使用tensorfow的具有一个隐藏层的样本NN模型如下:

The problem falls into Multivariate Regression category since the outputs are continuous value. Therefore, you can train a neural network (NN) having 4 output nodes and input feature vector of size 4. A sample NN model having one hidden layer using tensorfow is as follows:

import itertools
import numpy as np
from sklearn.preprocessing import StandardScaler
from tensorflow.python.keras.layers import Input, Dense
from tensorflow.python.keras.models import Model

A = [100, 120, 140, 160, 180, 200, 220, 240, 260, 280]
B = [300, 320, 340, 360, 380, 400, 420, 440, 460, 480]
C = [500, 520, 540, 560, 580, 600, 620, 640, 660, 680]

X_train = np.array(list(itertools.product(A, B, C)))
# X_train = np.random.random(size=(1000,3))
scaler = StandardScaler()
X = scaler.fit_transform(X_train)

Y_train = np.random.randint(0, 100, size=(1000, 4)).astype(float)  # Should load original label

X_test = np.random.random(size=(100, 3))
Y_test = np.random.randint(0, 100, size=(100, 4)).astype(float)

input = Input(shape=(3,))
hidden_layer_1 = Dense(25, activation='relu')(input)
output = Dense(4)(hidden_layer_1)

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

history = model.fit(X_train, Y_train, epochs=1000, batch_size=8)

result = model.predict(X_test)

这篇关于神经网络–预测多个变量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆