我创建了一个多图图,但我想选择并显示出错误最小的图,我应该怎么做?
figContour = plt.figure()
figContour.suptitle("Figure 3, Question 1(b): contour plots for various training sessions.")
Total_err = []
for i in range(9):
X,t = datasets.make_moons(n_samples=200, noise=0.2)
clf = MLPClassifier(hidden_layer_sizes=[3],
activation='tanh',
solver='sgd',
learning_rate_init=0.01,
tol=10.0**(-20),
max_iter=10000)
clf.fit(X,t)
acc = clf.score(X,t)
error = 1 - acc
print ("Error: [%s]" % error)
Total_err.append(error)
ax1 = figContour.add_subplot(3,3,i+1)
ax1.set_xlim(-6,6)
ax1.set_ylim(-6,6)
colors = np.array(["r","b"])
ax1.scatter(X[:, 0], X[:, 1], color=colors[t],s=0.1)
bonnerlib2.dfContour(clf,ax1)
plt.show()
smallest = np.argmin(Total_err)
答案 0 :(得分:0)
如果您不需要同时拥有两个版本的绘图,则可以创建轴列表,隐藏所有轴,并使用change_geometry
更新其位置:
import matplotlib.pyplot as plt
import numpy as np
fig, axes = plt.subplots(3, 3)
axes = axes.flatten()
metric = []
for i in range(9):
dat = np.random.exponential(1, (10, 2))
metric.append(dat.sum())
axes[i].set_xlim(-6,6)
axes[i].set_ylim(-6,6)
axes[i].scatter(dat[:, 0], dat[:, 1])
_min = np.argmin(metric)
[axes[i].set_visible(False) for i, _ in enumerate(axes) if i != _min]
axes[_min].change_geometry(1,1,1)