我有一个基础神经网络,我在Keras训练过。我正在研究学习速度和动量项的影响,我想绘制一个漂亮的三维图形,以显示学习速度和动量对准确性的影响。
我设法使用示例代码成功绘制了一个trisurf图,但每当我使用自己的数据时,我都会遇到错误。这些示例似乎使用了大约1000个值的numpy数组,而我只有大约6个不同的学习速率和动量值,给出了大小为6,6和36的numpy数组。当我尝试使用这些值绘制图形时,我得到了以下错误:
RuntimeError:qhull Delaunay三角测量计算错误: 单数输入数据(exitcode = 2)
我不理解这个错误消息,以及为什么它对示例数据起作用,而不是我自己的。有什么建议吗?
我的代码如下:
momentum_terms = np.array([0.00001,0.0001,0.001,0.01, 0.1, 1])
learning_rates = np.array([0.00001,0.0001,0.001,0.01, 0.1, 1])
train_accuracies = np.empty([36])
test_accuracies = np.empty([36])
for learning_rate in learning_rates:
for momentum in momentum_terms:
model = Sequential()
model.add(Dense(18, activation='relu', input_shape = (2,)))
model.add(Dense(18, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.summary()
model.compile(loss='binary_crossentropy',
optimizer=SGD(lr = learning_rate, momentum = momentum),
metrics=[binary_accuracy])
history = model.fit(x_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_data=(x_test, y_test))
score = model.evaluate(x_test, y_test, verbose=0)
np.append(train_accuracies, history.history['binary_accuracy'][-1] * 100)
np.append(test_accuracies, history.history['val_binary_accuracy'][-1] * 100)
x = momentum_terms
y = learning_rates
z = test_accuracies
ax = plt.axes(projection='3d')
ax.plot_trisurf(x, y, z, cmap='viridis', edgecolor='none');
plt.show()
答案 0 :(得分:2)
您没有提供足够的数据来生成3d图(see this related SO question)。不需要传递6,6和36,而是需要传递36,36和36.重做代码,以便在准确的情况下将每对动量项和学习速率项存储在循环中。
所以你应该:
x = [0.00001,0.00001,0.00001,0.00001,0.00001, 0.00001,0.0001, 0.0001,....]从学习率选择中获得36个值
y = [0.00001,0.0001,0.001,0.01,0.1, 1,0.00001, 0.0001,0.001,0.01,0.1,1 ......],36个值来自动量选择< / p>
z =上述每个组合的36个精度数组