stefan-jansen / machine-learning-for-trading

Code for Machine Learning for Algorithmic Trading, 2nd edition.
https://ml4trading.io
13.52k stars 4.26k forks source link

04_q_learning_for_trading -> experience_replay(self) --> predict q values gives shape mismatch error #288

Closed yeonmo317 closed 1 year ago

yeonmo317 commented 1 year ago

Error:

This line of code: q_values[[self.idx, actions]] = targets Gives an error: Exception has occurred: ValueError shape mismatch: value array of shape (4096,) could not be broadcast to indexing result of shape (2,4096,3) bug reported v2

Steps to reproduce:

run 04_q_learning_for_trading.ipynb

Environment:

python 3.9

Frxljord commented 1 year ago

I found by replacing line 123 with :

    for i in self.idx:
        action = actions[i]
        q_values[self.idx][action] = targets[i]

the training works!