I have 2 values for predict label, -1 or 1.
The learning looks good with LSTM or with Dense, but the prediction is always the same with different predict datasets, changing the layers to Dense does not change the prediction, maybe I am doing something wrong.
Here is the code
// set up data arrays
float[,,] training_data = new float[training.Count(), 12, 200];
float[,,] testing_data = new float[testing.Count(), 12, 200];
float[,,] predict_data = new float[1, 12, 200];
IList<float> training_labels = new List<float>();
IList<float> testing_labels = new List<float>();
// Load Data and add to arrays
...
...
/////////////////////////
NDarray train_y = np.array(training_labels.ToArray());
NDarray train_x = np.array(training_data);
NDarray test_y = np.array(testing_labels.ToArray());
NDarray test_x = np.array(testing_data);
NDarray predict_x = np.array(predict_data);
train_y = Util.ToCategorical(train_y, 2);
test_y = Util.ToCategorical(test_y, 2);
//Build functional model
var model = new Sequential();
model.Add(new Input(shape: new Keras.Shape(12, 200)));
model.Add(new BatchNormalization());
model.Add(new LSTM(128, activation: "tanh", recurrent_activation: "sigmoid", return_sequences: false));
model.Add(new Dropout(0.2));
model.Add(new Dense(32, activation: "relu"));
model.Add(new Dense(2, activation: "softmax"));
model.Compile(optimizer: new SGD(), loss: "binary_crossentropy", metrics: new string[] { "accuracy" });
model.Summary();
var history = model.Fit(train_x, train_y, batch_size: 1, epochs: 1, verbose: 1, validation_data: new NDarray[] { test_x, test_y });
var score = model.Evaluate(test_x, test_y, verbose: 2);
Console.WriteLine($"Test loss: {score[0]}");
Console.WriteLine($"Test accuracy: {score[1]}");
NDarray predicted=model.Predict(predict_x, verbose: 2);
Console.WriteLine($"Prediction: {predicted[0][0]*100}");
Console.WriteLine($"Prediction: {predicted[0][1]*100}");
And this is the ouput
483/483 [==============================]
- 9s 6ms/step - loss: 0.1989 - accuracy: 0.9633 - val_loss: 0.0416 - val_accuracy: 1.0000
4/4 - 0s - loss: 0.0416 - accuracy: 1.0000
Test loss: 0.04155446216464043
Test accuracy: 1
1/1 - 0s
Prediction: 0.0010418787496746518
Prediction: 99.99896287918091
The same predict data used in ML.net gives a different results, but with ML.Net the accuracy is only 0.6, that's why I need a deep learning