yacoubb / stock-trading-ml

A stock trading bot that uses machine learning to make price predictions.
GNU General Public License v3.0
624 stars 257 forks source link

ValueError: Data cardinality is ambiguous: #18

Open vdfdfhgbstdh opened 4 years ago

vdfdfhgbstdh commented 4 years ago

I get this error when running the trading_algo.py:

`ValueError Traceback (most recent call last)

in () ----> 1 model.predict([[ohlcv], [ind]]) 3 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py in __init__(self, x, y, sample_weights, sample_weight_modes, batch_size, epochs, steps, shuffle, **kwargs) 280 label, ", ".join(str(i.shape[0]) for i in nest.flatten(data))) 281 msg += "Please provide data which shares the same first dimension." --> 282 raise ValueError(msg) 283 num_samples = num_samples.pop() 284 ` ValueError: Data cardinality is ambiguous: x sizes: 50, 1 Please provide data which shares the same first dimension. Can anyone advise what the issue is?
OdincoGaming commented 4 years ago

same issue here, saw in some tensorflow threads that its due to inputs with a different number of values, IE ohlcv and ind are different lengths, but I havent found a fix for it yet. ill keep you updated if I find something.

OdincoGaming commented 4 years ago

so I ran it in a jupyter notebook to get a closer look at the variables and ohlcv_test has lengths of (675, 50, 5) while tech_ind_test has lengths of (675, 1) and the error is returning x size: 50, 1 so it seems to be skipping over the 675 values for both arrays and trying to compare the 50 and the 1. not sure what to do about it, but that seems to be whats happening.

NicBT commented 4 years ago

i found the problem and the fix: In predicted_price_tomorrow = np.squeeze(y_normaliser.inverse_transform(model.predict([[ohlcv], [ind]]))), model.predict() is expecting (in this case) a list of arrays. Instead, we are currently passing in a list of lists. To fix this, all you need to do is change model.predict([[ohlcv], [ind]]) to model.predict([np.array([ohlcv]), np.array([ind])])