我正在使用Tensorflow。NET学习一些神经网络。我曾尝试过其他框架,但Keras似乎是目前最好的框架之一。然而,我一直在建立自己的基本时间序列预测。
int[,] X = new int[,] { {1, 2, 3 },
{2, 3, 4 },
{3, 4, 5 },
{4, 5, 6 } };
int[] Y = new int[] { 4 , 5 , 6 , 7 };
NDArray ndX = np.array(X);
NDArray ndY = np.array(Y);
Tensorflow.Keras.ArgsDefinition.SequentialArgs sequentialArgs = new Tensorflow.Keras.ArgsDefinition.SequentialArgs();
Tensorflow.Keras.Engine.Sequential model = new Tensorflow.Keras.Engine.Sequential(sequentialArgs);
Tensorflow.Keras.ArgsDefinition.Rnn.LSTMArgs lstmArgs = new Tensorflow.Keras.ArgsDefinition.Rnn.LSTMArgs();
lstmArgs.Units = 4;
lstmArgs.InputShape = new Shape(1,4);
lstmArgs.ReturnSequences = false;
lstmArgs.Activation = new Activations().Tanh;
lstmArgs.RecurrentActivation = new Activations().Sigmoid;
model.add(new Tensorflow.Keras.Layers.Rnn.LSTM(lstmArgs));
Tensorflow.Keras.ArgsDefinition.DenseArgs denseArgs = new Tensorflow.Keras.ArgsDefinition.DenseArgs();
denseArgs.Units = 2;
model.add(new Tensorflow.Keras.Layers.Dense(denseArgs));
model.compile("adam", "mse", new string[]{"accuracy"});
model.fit(ndX, ndY, batch_size:4, epochs:200, verbose:2);
最后一行,model.fit是我在标题中得到信息的地方。
我已经处理了输入数组的维度,将其更改为3个维度,将Y数组更改为2个维度。我还调整了lstmArgs.InputShape,但似乎没有任何效果。我肯定没有完全理解输入数组的维度之间的关系。