jinglescode / time-series-forecasting-tensorflowjs

Pull stock prices from online API and perform predictions using Long Short Term Memory (LSTM) with TensorFlow.js framework
https://jinglescode.github.io/time-series-forecasting-tensorflowjs/
Apache License 2.0
154 stars 52 forks source link

Strange results #7

Closed kaykyr closed 3 years ago

kaykyr commented 3 years ago

Hello this is a very interesting project. I tried with the default graphics (MSFT) and I got a great result.

But now, I am trying to train a model for EURUSD asset from Forex (15 minutes timeframe)

Screen Shot 2021-04-08 at 23 58 33

But I am getting this result... and sometimes is just a rect line...

I am trying to understand this better, I am not experienced with neural networks before, but may you able to help me to understand?

Thank you!

kaykyr commented 3 years ago

Or may someone can recommend any content to study and understand it better? Thanks

jinglescode commented 3 years ago

Hi, could you upload a more complete picture of the graph, with the legends and the axis. And also the parameters you have used.

kaykyr commented 3 years ago

Hi, could you upload a more complete picture of the graph, with the legends and the axis. And also the parameters you have used.

Hello! In attach the JSON containing EURUSD (~6.000 5 minutes candles) data: https://drive.google.com/file/d/1XXiUfSL9eBkPjUhAnu4mTkH1jdceieTz/view?usp=sharing

I am using the same algorithm with the following parameters:

Screen Shot 2021-04-09 at 00 40 09

Training Dataset Size: 98 Epochs: 25 Learning Rate: 0,01 Hidden LSTM Layers: 4 Simple Moving Average Period: 20

Screen Shot 2021-04-09 at 00 40 37

I also tried with different training dataset size, epochs and SMA periods... The result are always the same.

This is the training chart: Screen Shot 2021-04-09 at 00 46 52

This is the validation chart: Screen Shot 2021-04-09 at 00 47 23

And this is the predict chart: Screen Shot 2021-04-09 at 00 47 51

This trained model download: https://drive.google.com/file/d/1n7eMn-OTMK1ziSqI-2IOKOFR3jLrm_ZH/view?usp=sharing

fgabrielbr commented 3 years ago

I am facing exactly the same problem

clarklight commented 3 years ago

I am seeing the same result as well, i forked a version and trained the code, i see the same result locally as well. The only difference between your initial commit is this 2 lines.

let X = inputs.slice(0, Math.floor(trainingsize / 100 inputs.length)); let Y = outputs.slice(0, Math.floor(trainingsize / 100 outputs.length));

The current version doesnt have that, not sure if its anything to do with the issue. (I am still learning, so not sure if thats the issue).

Also on this link https://jinglescode.github.io/time-series-forecasting-tensorflowjs/ Followed all the settings you used on your readme, and i also got a flatline for validating the prediction.

jinglescode commented 3 years ago

This is the challenge of machine learning, that a model, out of the box, doesn't work for all kinds of data. There is a lot of parameter tuning involve. There may need to do more feature engineering. Or there is a need to change the model architecture.

Indeed, you can see that you are not the only one who faced this problem:

I do not have an answer for you, unfortunately. Some suggestions would be:

jinglescode commented 3 years ago

@kaykyr, it's really strange you are getting a flat line on the training set too. I think have to debug (doing lots of console.log) and figure out what is the issue. At the minimum, you should get the model to overfit on the training set.

kaykyr commented 3 years ago

@kaykyr, it's really strange you are getting a flat line on the training set too. I think have to debug (doing lots of console.log) and figure out what is the issue. At the minimum, you should get the model to overfit on the training set.

Hey, thank you!

It's very strange, but I built the same model with python with latest versions (Keras/Tensorflow) I got other result, but looks like it's predicting to the future the same thing of the past.

But, it's ok, now I know that this is a thing that needs too much effort to works great, I'll keep learning and improving my model.