Reputation: 65
I am building a Conv1D model with train data (28659, 257) and test data (5053, 257), but I am facing a value error that says: expected min_ndim=3, found ndim=2. Full shape received: [None, 256]
print(train_data.shape)
print(test_data.shape)
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=5, activation='relu', input_shape=(256,1)))
model.add(Conv1D(filters=64, kernel_size=3, activation='relu'))
model.add(Dropout(0.5))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(8, activation='relu'))
model.add(Dense(2, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])
model.summary()
opt = keras.optimizers.Adam(learning_rate=0.01)
model.compile(loss='CategoricalCrossentropy', optimizer=opt, metrics=['accuracy'])
history = model.fit(train_data.values[:, 0:256], to_categorical(train_data.values[:, 256]), epochs=180, batch_size=500)
y_pred = model.predict(test_data.values[:, 0:256])
y_pred = model.predict(test_data.values[:,0:256])
y_pred = (y_pred > 0.5)
accuracy = metrics.accuracy_score(to_categorical(test_data.values[:,256]),y_pred)
print(f'Testing accuracy of the model is {accuracy*100:.4f}%')
The error is from the fit(), but I cannot figure my mistake with the calculation! Any help is appreciated!
Upvotes: 1
Views: 419
Reputation: 1020
try to reshape your train and test data :
X_train=np.reshape(train_data,(train_data.shape[0], train_data.shape[1],1))
X_test=np.reshape(test_data,(test_data.shape[0], test_data.shape[1],1))
You can't feed values like : [1,2,3,4]
, you have to feed your values like [[1],[2],[3],[4]]
Upvotes: 1