因此,我一直试图查看我的网络的决策边界,出于某种原因,当我运行它时,它没有给我任何输出。我从这里那里拿走了这个函数
它不会产生任何错误,它只会结束运行。
# Fit the model also history to map the model
history = model.fit(X, Y,validation_split=0.30, epochs=10, batch_size=1000, verbose= 1)
# evaluate the model
scores = model.evaluate(X, Y)
def plot_decision_boundary(X, y, model, steps=1000, cmap='Paired'):
"""
Function to plot the decision boundary and data points of a model.
Data points are colored based on their actual label.
"""
cmap = plt.get_cmap(cmap)
# Define region of interest by data limits
xmin, xmax = X[:,0].min() - 1, X[:,0].max() + 1
ymin, ymax = X[:,1].min() - 1, X[:,1].max() + 1
steps = 1000
x_span = np.linspace(xmin, xmax, steps)
y_span = np.linspace(ymin, ymax, steps)
xx, yy = np.meshgrid(x_span, y_span)
# Make predictions across region of interest
labels = model.predict(np.c_[xx.ravel(), yy.ravel()])
# Plot decision boundary in region of interest
z = labels.reshape(xx.shape)
fig, ax = plt.subplots()
ax.contourf(xx, yy, z, cmap=cmap, alpha=0.5)
# Get predicted labels on training data and plot
train_labels = model.predict(X)
ax.scatter(X[:,0], X[:,1], c=y, cmap=cmap, lw=0)
return fig, ax
plot_decision_boundary(X, Y, model, cmap='RdBu')我对这个功能并没有做太多的改动。我在这里错过了什么?
发布于 2018-12-12 11:19:49
函数plot_decision_boundary()构造一个fig和一个ax对象,这些对象在结尾处返回。在您的代码中,当这些对象被返回时,没有任何东西可以处理。仅仅因为一个函数返回无花果和ax并不意味着它们会被自动绘制。
解决方案很简单,只需打电话
plt.show()调用决策边界函数之后。此部分在示例代码中经常被省略。我认为这是因为有几种方法可以生成窗口并显示情节(您还可以将其直接保存到文件中,在这种情况下,不需要show()语句)。
https://stackoverflow.com/questions/53741412
复制相似问题