0

I'm using a neural network to classify text, and the label of the training data is 0 or 1(i.e. binary classification). It works well in the training and evaluating process, but the prediction output is float values rather than integer 0 or 1. How could I always get integer results? Do i need to manually convert them or change network parameters?

model = Sequential()
e = Embedding(vocab_size, embedding_dim, weights=[embedding_matrix], 
input_length=max_length, trainable=False)
model.add(e)
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(1, activation='sigmoid'))

# compile
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['acc'])
print(model.summary())

# fit
model.fit(padded_docs, labels, epochs=5, verbose=2)

# eval
loss, accuracy = model.evaluate(padded_docs, labels, verbose=0)
print('Accuracy: %f' % (accuracy*100))

# predict
result = model.predict(padded_docs_test, verbose=2)
realjin
  • 101
  • 1

1 Answers1

1

Numerical predictions - which I assume are predicted probabilities - are exactly what a statistical method should output, for reasons given in Classification probability threshold.

I see that you are calculating accuracies. I recommend Why is accuracy not the best measure for assessing classification models? and Is accuracy an improper scoring rule in a binary classification setting?

Stephan Kolassa
  • 95,027
  • 13
  • 197
  • 357