huseinzol05 / Stock-Prediction-Models

Gathers machine learning and deep learning models for Stock forecasting including trading bots and simulations
Apache License 2.0
7.84k stars 2.78k forks source link

Problem evolution-strategy-bayesian-agent indices #4

Closed bitnom closed 5 years ago

bitnom commented 5 years ago

In the model of https://github.com/huseinzol05/Stock-Prediction-Models/blob/master/agent/evolution-strategy-bayesian-agent.ipynb

I get the following:

print('Best AGENT accuracy value: %f' % NN_BAYESIAN.res['max']['max_val'])
      3 print('Best AGENT parameters: ', NN_BAYESIAN.res['max']['max_params'])

TypeError: list indices must be integers or slices, not str

error

Could you perhaps clear up those 2 lines and provide some context there? Thanks for the great research.

bitnom commented 5 years ago

Maybe you are using older version (Pre-1.0) of BayesianOptimization?

AlconDivino commented 5 years ago

i have the same problem right now. using v 1.0.1 of BayesianOptimization

bitnom commented 5 years ago

i have the same problem right now. using v 1.0.1 of BayesianOptimization

I think we're going to have to come together and upgrade some of this code. In the meantime, I suggest rolling back package versions. I know people often like to horde market trading code rather than share forks but in this case, this is a really good repo we should keep up to some degree. I'll pull request or fork when I get to that point. I suggest others do the same.

AlconDivino commented 5 years ago

Okay quick solution: Use print(NN_BAYESIAN.max) to get the parameters NN_BAYESIAN.max will return a json object with 'params' and 'target' for the best parameters. I think they changed it from v1.0.0 on and they are using an older version :D

bitnom commented 5 years ago

Okay quick solution: Use print(NN_BAYESIAN.max) to get the parameters NN_BAYESIAN.max will return a json object with 'params' and 'target' for the best parameters. I think they changed it from v1.0.0 on and they are using an older version :D

nice thx. Can you link to that doc? I tried to find it.

bitnom commented 5 years ago

Okay quick solution: Use print(NN_BAYESIAN.max) to get the parameters NN_BAYESIAN.max will return a json object with 'params' and 'target' for the best parameters. I think they changed it from v1.0.0 on and they are using an older version :D

Also, are you getting this:

evolution-strategy-bayesian-agent.py:88: RuntimeWarning: invalid value encountered in true_divide

for the line:

rewards = (rewards - np.mean(rewards)) / np.std(rewards)

This is loading the GOOG.csv file.

Part of the time the script crashes completely with:

evolution-strategy-bayesian-agent.py:88: RuntimeWarning: invalid value encountered in true_divide
  rewards = (rewards - np.mean(rewards)) / np.std(rewards)
Traceback (most recent call last):
  File "evolution-strategy-bayesian-agent.py", line 360, in <module>
    agent.fit(500, 100)
  File "evolution-strategy-bayesian-agent.py", line 198, in fit
    self.es.train(iterations, print_every = checkpoint)
  File "evolution-strategy-bayesian-agent.py", line 87, in train
    rewards[k] = self.reward_function(weights_population)
  File "evolution-strategy-bayesian-agent.py", line 172, in get_reward
    action, buy = self.act(state)
  File "evolution-strategy-bayesian-agent.py", line 162, in act
    return np.argmax(decision[0]), int(buy[0])
ValueError: cannot convert float NaN to integer
AlconDivino commented 5 years ago

I only ran the script until the NN_BAYESIAN.maximise function. I used the GOOG.csv file too and didn't encounter the crash.

The warning is spilled by some iterations tho. If you look at the evolution-strategy-bayesian-agent.ipynb file you see the same warning:

evolution-strategy-bayesian-agent.py:88: RuntimeWarning: invalid value encountered in true_divide Screenshot from 2019-03-20 01-24-23

AlconDivino commented 5 years ago

Also did you notice the "stop after 500 iteration with investment" in the file there is only written print('stop after 100 iteration with investment %f' % (investment)) I think they also adjusted the code without adjusting the output from an earlier version.

bitnom commented 5 years ago

I only ran the script until the NN_BAYESIAN.maximise function. I used the GOOG.csv file too and didn't encounter the crash.

The warning is spilled by some iterations tho. If you look at the evolution-strategy-bayesian-agent.ipynb file you see the same warning:

evolution-strategy-bayesian-agent.py:88: RuntimeWarning: invalid value encountered in true_divide Screenshot from 2019-03-20 01-24-23

I am still trying to figure that out. I have submitted a request here. I improved a bit by passing bayes results automatically to agent: https://github.com/huseinzol05/Stock-Prediction-Models/commit/061d50b0ae2fc89b00982b6c0a8ad13d1b3354c5 viewable here: https://github.com/huseinzol05/Stock-Prediction-Models/blob/061d50b0ae2fc89b00982b6c0a8ad13d1b3354c5/agent/evolution-strategy-bayesian-agent.ipynb

Still some problems there but on the right track.

huseinzol05 commented 5 years ago

Hi! I will check it out later after my working hour, thanks for this contribution!

bitnom commented 5 years ago

Hi! I will check it out later after my working hour, thanks for this contribution!

Awesome. We just need help getting rid of these errors from it.

bitnom commented 5 years ago

Also did you notice the "stop after 500 iteration with investment" in the file there is only written print('stop after 100 iteration with investment %f' % (investment)) I think they also adjusted the code without adjusting the output from an earlier version.

Will take a look at that now.

AlconDivino commented 5 years ago

Another thing. NN_BAYESIAN.max returns the json object with 'target' and 'params'. I it right to asume that 'target' is the accuracy value in the previous version?

bitnom commented 5 years ago

Another thing. NN_BAYESIAN.max returns the json object with 'target' and 'params'. I it right to asume that 'target' is the accuracy value in the previous version?

do a fork and we can commit to it together more quickly. ping me here right after you fork it

bitnom commented 5 years ago

Another thing. NN_BAYESIAN.max returns the json object with 'target' and 'params'. I it right to asume that 'target' is the accuracy value in the previous version?

here we go. Let's work over here: https://github.com/TensorTom/Stock-Prediction-Models

bitnom commented 5 years ago

I got it working. Please see here: https://github.com/huseinzol05/Stock-Prediction-Models/issues/5

huseinzol05 commented 5 years ago

I improve the notebooks, nes-with-bayesian, nes

Print versions use,

!pip3 install bayesian-optimization==0.6 --user
seaborn==0.9.0
pandas==0.23.4
numpy==1.14.5
matplotlib==3.0.2

And new results,

evolution strategy agent READ MORE

total gained 11037.529911, total investment 110.375299 %

evolution strategy with bayesian agent READ MORE

total gained 13295.469683, total investment 132.954697 %