Closed AntoineDubois closed 1 year ago
I have found the bug.
When the input is multi-dimensional, model.predict does:
model.network(x[i]). Thus, x[i] has 1 dimension instead of 2.
As a quick fix, I did:
if x.dim() == 1: x = x[None,:]
I think it would be nice to fix this 😀
Hey @AntoineDubois! Thanks for reaching out.
Could you share a code snippet? I don't know if I understood your problem completely. You should pass 2 dimensional arrays in both fit and predict methods. The y array must be a 2 dimensional array with 1 column. If the X array has only one input, it must be a 2 dimensional array with 1 column as well. If the X array is a multiple input array, it must be a 2 dimensional array with n columns, where n is the number of inputs you have. That is how it should be used. Is that your case?
Y.dim() =2, X.dim()=2
and the shapes are coherent. The NARXNN.fit works well.
With the same inputs X and Y, NARXNN.predict does X[i]. X[i].dim() =1 and the neural network cannot pass the input.
I am suspecting the problem comes from _narmax_predict(self, X, y_initial, forecast_horizon) in class ModelPredict.
To fix this issue, I added if x.dim() == 1: x = x[None,:]
in ModelNN.forward:
def forward(self, x):\\ if x.dim() == 1: x = x[None,:]\\ x = self.layer(x)\\ x = self.act(x)
I hope it helps.
fixed in v0.3.0
Hello, I use a neural network to predict 1-dim Y from 30-dim X. Fitting works. However, narx_net.predict(X=X_valid, y=Y_valid) returns "RuntimeError: input must have 3 dimensions, got 2" How can I fix this error?
Thank you for this beautiful package