ValueError: Input arrays should have the same number of samples as target arrays.

977 views
Skip to first unread message

Siva Kumar

unread,
Sep 15, 2019, 4:20:38 AM9/15/19
to Keras-users
This is my hyper parameter.
top_words = 5000
maxlen = 400
batch_size = 32
embedding_dims = 50
filters = 250
kernel_size = 3
hidden_dims = 250
epochs = 1

This is my shape of my dataframe.
print(x_train.shape)
print(y_train.shape)
print(x_test.shape)
print(y_test.shape)

(4681, 2) (4681,) (1171, 2) (1171,)

This is my Model.

model = Sequential()
model.add(Embedding(top_words, embedding_dims, input_length=maxlen))
model.add(Dropout(0.2))
model.add(Conv1D(filters, kernel_size, padding='valid', activation='relu', strides=1))
model.add(GlobalMaxPooling1D())
model.add(Dense(hidden_dims))
model.add(Dropout(0.2))
model.add(Activation('relu'))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=batch_size, epochs=ep, validation_data=(x_test, y_test))
scores = model.evaluate(x_train, y_train, batch_size=batch_size,verbose=1)

My Error is
ValueError: Input arrays should have the same number of samples as target arrays. Found 2 input samples and 4681 target samples.

Kindly give a valuable suggestion, to rectify the error.

Lance Norskog

unread,
Sep 16, 2019, 5:38:56 PM9/16/19
to Siva Kumar, Keras-users
The shapes should be:
(4681, 2) (4681, 1) (1171, 2) (1171, 1)

There is a numpy function that 'Adds a 1-sized dimension at index "axis"'.

You would preprocess y_train and y_test with:
y_train = numpy.expand_dims(y_train, axis=-1)
and the same with y_test.

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/01d6f0cd-bbb7-4c00-9141-cbc427cb8d32%40googlegroups.com.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA
Reply all
Reply to author
Forward
0 new messages