Explore Courses Blog Tutorials Interview Questions
0 votes
in Machine Learning by (19k points)

I am working on a simple CNN classifier using keras with the tensorflow background.

def cnnKeras(training_data, training_labels, test_data, test_labels, n_dim):

print("Initiating CNN")

seed = 8


model = Sequential()

model.add(Convolution2D(64, 1, 1, init='glorot_uniform', border_mode='valid',

                        input_shape=(16, 1, 1), activation='relu'))

model.add(MaxPooling2D(pool_size=(1, 1)))

model.add(Convolution2D(32, 1, 1, init='glorot_uniform', activation='relu'))

model.add(MaxPooling2D(pool_size=(1, 1)))



model.add(Dense(128, activation='relu'))


model.add(Dense(64, activation='relu'))

model.add(Dense(1, activation='softmax'))

# Compile model


              optimizer='adam', metrics=['accuracy']), training_labels, validation_data=(

    test_data, test_labels), nb_epoch=30, batch_size=8, verbose=2)

scores = model.evaluate(test_data, test_labels, verbose=1)

print("Baseline Error: %.2f%%" % (100 - scores[1] * 100))


return None

It is a binary classification problem, but I keep getting the message Received a label value of 1 which is outside the valid range of [0, 1) which does not make any sense to me. Any suggestions?

1 Answer

0 votes
by (33.1k points)

The range (0, 1) means every number between 0 and 1, excluding 1. So 1 is not a value in the range [0, 1).

The issue could be due to your choice of the loss function. 

For binary classification, binary_crossentropy should be a better choice.

For more details on CNN, study Artificial Intelligence Course. For more details on Keras, learn Machine Learning Course.

Hope this answer helps.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers


104k users

Browse Categories