【发布时间】:2018-05-28 18:47:50
【问题描述】:
我正在学习神经网络,我在 Keras 中构建了一个简单的神经网络,用于来自 UCI 机器学习存储库的虹膜数据集分类。我使用了一个带有 8 个隐藏节点的隐藏层网络。 Adam 优化器使用 0.0005 的学习率并运行 200 个 Epoch。 Softmax 用于输出,损失为分类交叉熵。我得到以下学习曲线。
如您所见,准确度的学习曲线有很多平坦区域,我不明白为什么。错误似乎在不断减少,但准确性似乎并没有以同样的方式增加。准确度学习曲线中的平坦区域意味着什么?为什么即使误差似乎在减少,这些区域的准确度却没有增加?
这是训练中的正常现象还是我在这里做错了什么?
dataframe = pd.read_csv("iris.csv", header=None)
dataset = dataframe.values
X = dataset[:,0:4].astype(float)
y = dataset[:,4]
scalar = StandardScaler()
X = scalar.fit_transform(X)
label_encoder = LabelEncoder()
y = label_encoder.fit_transform(y)
encoder = OneHotEncoder()
y = encoder.fit_transform(y.reshape(-1,1)).toarray()
# create model
model = Sequential()
model.add(Dense(8, input_dim=4, activation='relu'))
model.add(Dense(3, activation='softmax'))
# Compile model
adam = optimizers.Adam(lr=0.0005, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
model.compile(loss='categorical_crossentropy',
optimizer=adam,
metrics=['accuracy'])
# Fit the model
log = model.fit(X, y, epochs=200, batch_size=5, validation_split=0.2)
fig = plt.figure()
fig.suptitle("Adam, lr=0.0006, one hidden layer")
ax = fig.add_subplot(1,2,1)
ax.set_title('Cost')
ax.plot(log.history['loss'], label='Training')
ax.plot(log.history['val_loss'], label='Validation')
ax.legend()
ax = fig.add_subplot(1,2,2)
ax.set_title('Accuracy')
ax.plot(log.history['acc'], label='Training')
ax.plot(log.history['val_acc'], label='Validation')
ax.legend()
fig.show()
【问题讨论】:
标签: machine-learning neural-network keras classification loss