是否可以将数组传入神经网络感知器?

问题描述 投票:0回答:2

我正在尝试建立一个神经网络来识别艾略特波浪,我想知道是否可以将数组数组传递到感知器中?我的计划是将大小为 4 的数组([开盘价、收盘价、最高价、最低价])传递到每个感知器中。如果是这样,加权平均计算将如何进行?如何使用 Python Keras 库来进行计算?谢谢!

python tensorflow machine-learning keras neural-network
2个回答
3
投票

这是一个非常标准的全连接神经网络构建。我假设您有分类问题:

from keras.layers import Input, Dense
from keras.models import Model

# I assume that x is the array containing the training data
# the shape of x should be (num_samples, 4)
# The array containing the test data is named y and is 
# one-hot encoded with a shape of (num_samples, num_classes)
# num_samples is the number of samples in your training set
# num_classes is the number of classes you have
# e.g. is a binary classification problem num_classes=2

# First, we'll define the architecture of the network
inp = Input(shape=(4,)) # you have 4 features
hidden = Dense(10, activation='sigmoid')(inp)  # 10 neurons in your hidden layer
out = Dense(num_classes, activation='softmax')(hidden)  

# Create the model
model = Model(inputs=[inp], outputs=[out])

# Compile the model and define the loss function and optimizer
model.compile(loss='categorical_crossentropy', optimizer='adam', 
              metrics=['accuracy'])
# feel free to change these to suit your needs

# Train the model
model.fit(x, y, epochs=10, batch_size=512)
# train the model for 10 epochs with a batch size of 512

0
投票

每个数组值有不同的权重吗?

我认为你会的,因为它们听起来像是变量名称不同的语义。

这与拥有 4 个独立的网络相同,但也许这样更容易编写代码。

所以我说,出于这个原因,这个想法很好。

© www.soinside.com 2019 - 2024. All rights reserved.