简体   繁体   English

Keras 二元分类器教程示例仅提供 50% 的验证准确度

[英]Keras Binary Classifier Tutorial Example gives only 50% validation accuracy

Keras Binary Classifier Tutorial Example gives only 50% validation accuracy. Keras 二元分类器教程示例仅提供 50% 的验证准确度。 The near 50% accuracy can be gotten from an un-trained classifier itself for binary classification.近 50% 的准确率可以从未经训练的分类器本身获得,用于二元分类。

This example is straight from https://keras.io/getting-started/sequential-model-guide/这个例子直接来自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纪元 50/50 1000/1000 [==============================] - 0s 211us/样本 - 损失:0.6905 - 准确度: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.如果您使用random示例训练分类器,您将始终获得 aprrox。 50% accuracy at validation data here represented by x_test .此处由x_test表示的验证数据准确率为 50%。 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.这就是随机准确率(即 50-50%)出现的原因。 The more epoch you test the training set the more accuracy you will get on training set as an effect of overfitting .您测试训练集的时期越多,由于过度拟合,您在训练集上获得的准确度就越高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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