简体   繁体   中英

Keras Binary Classifier Tutorial Example gives only 50% validation accuracy

Keras Binary Classifier Tutorial Example gives only 50% validation accuracy. The near 50% accuracy can be gotten from an un-trained classifier itself for binary classification.

This example is straight from https://keras.io/getting-started/sequential-model-guide/

import numpy as np
import tensorflow as tf

from tensorflow_core.python.keras.models import Sequential
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout

np.random.seed(10)

# Generate dummy data
x_train = np.random.random((1000, 20))
y_train = np.random.randint(2, size=(1000, 1))

x_test = np.random.random((800, 20))
y_test = np.random.randint(2, size=(800, 1))

model = Sequential()
model.add(Dense(64, input_dim=20, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))

model.compile(loss='binary_crossentropy',
              optimizer='rmsprop',
              metrics=['accuracy'])

model.fit(x_train, y_train,
          epochs=50,
          batch_size=128,
          validation_data=(x_test, y_test))
score = model.evaluate(x_test, y_test, batch_size=128)

Accuracy output.

  • I tried with multiple trials.
  • Increased the number of hidden layers

Epoch 50/50 1000/1000 [==============================] - 0s 211us/sample - loss: 0.6905 - accuracy: 0.5410 - val_loss: 0.6959 - val_accuracy: 0.4812

Could someone help me understand if anything is wrong here?

  • How to increase the accuracy for this "example" problem presented in the tutorial?

If you train a classifier with random examples, you will always get aprrox. 50% accuracy at validation data here represented by x_test . It is because your training samples get trained with random classes. Also the validation or test set has been assigned to random classes. This is why the random accuracy ie 50-50% occurs. The more epoch you test the training set the more accuracy you will get on training set as an effect of overfitting .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM