Hi Gang!
I am building my first ML model in the research environment. It's an LSTM model using PyTorch. My goal is to create a model that I can feed my custom indicator values into as features.
I am asking for the community's help because I am running into some errors. I have no background in data or ML, so I am praying that someone much smarter than me can help me understand what's wrong.
Ignore main.py and the backtest! Just generic ones to allow attaching.
~~~~~~~~~~~~~~~~~~~~
The actual errors are:
[7] “input_size = X_train.shape[2]” produces“IndexError: tuple index out of range"
[8] “outputs = model(inputs)" produces“RuntimeError: For unbatched 2-D input, hx and cx should also be 2-D but got (3-D, 3-D) tensors”
~~~~~~~~~~~~~~~~~~~~
From what I've picked up, there are issues with “reshaping” and “batching," which unfortunately aren't terms I'm familiar with (my brain starts smoking whenever I see an .iloc or .flatten).
Thank y'all in advance!
Eric Kao
I have resolve the issues by rewriting the code to as follows:
Adam W
Glad to see you figured it out. FYI, the reason behind the error is because LSTM/RNN models accept input tensors of shape (N, T, K), where N is the number of sequences, T are timesteps in each sequence, and K is the dimensionality of the features.
Since you mentioned that you are planning on using other features, be careful with some of the reshape logic in your updated code as it won't work as expected with more than 1 feature. To generalize your code to multiple features, simplest way to reshape it properly is to do something like
Batching just means that during training you will pass in batches of sequences in each training step, i.e. split N into some smaller batches, for stochastic gradient descent. I would also suggest starting with a simpler model (e.g. feedforward neural network, random forest, etc) if you aren't that familiar with RNNs as they have some nuances, especially for financial data.
Eric Kao
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!