Reputation: 649
I have an x_test data:
x_test.shape
Out[11]: (13096, 30)
x_test.size
Out[16]: 392880
When I launch the prediction it return an error:
ValueError: Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (13096, 30)
My code is very simple, I'm trying to run the predict function:
test_df= pd.read_csv("Path_data")
model = load_model.("path_model")
Xnew = np.array(test_df)
# make a prediction
predictions = model.predict_classes(Xnew)
Model summary:
Model: "sequential_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_1 (LSTM) (None, 50, 100) 50400
_________________________________________________________________
dropout_1 (Dropout) (None, 50, 100) 0
_________________________________________________________________
lstm_2 (LSTM) (None, 50) 30200
_________________________________________________________________
dropout_2 (Dropout) (None, 50) 0
_________________________________________________________________
dense_1 (Dense) (None, 1) 51
=================================================================
Total params: 80,651
Trainable params: 80,651
Non-trainable params: 0
Someone please can tell me how can I resolve this issue ? Thank you
Upvotes: 0
Views: 56
Reputation: 2689
This is dimension mismatch, the model expect to have a data record itself as an array of arrays, ie, if you have an image i, it expects, np.array([i])
, Try :
x_train = np.array([ [i] for i in x_train])
This will increment the dimension by 1
Upvotes: 1
Reputation: 39
Your variable x_test should have the input dimensions required by the LSTM layer which is a 3D tensor with shape [batch, timesteps, feature]
Upvotes: 1