Input shape error

I've this item:
['6', '1', '6', '843537', '3', '0', '5', '1006709', '3', '1', '4']
with shape: (11,)

but when go to predict with:

print(np.array(data).shape)
data = np.expand_dims(data, axis=0)
print('Predict: ' + model.predict(sc.transform(data)))

i get this error:

ValueError: Input 0 of layer sequential_2 is incompatible with the layer: expected shape=(None, 1, 11), found shape=(None, 11)

how can I do the fix?

Topic keras scikit-learn python

Category Data Science


You simply need to add another dimension to your data, you can either use numpy.expand_dims again or use numpy indexing to add the two extra dimensions at once:

data = np.expand_dims(np.expand_dims(data, axis=0), axis=0)
# or
data = data[None, None, :]

print(data.shape)
# (1, 1, 11)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.