【发布时间】:2021-08-14 09:03:42
【问题描述】:
这是我用来打印 100 mnist 数据的原始未简化图片的代码,但它不断给我一个错误。即使尝试了很多,我也找不到解决方案。征求意见
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784')
X = mnist["data"]
y = mnist["target"]
X_train, X_test, y_train, y_test = X[:60000], X[60000:], y[:60000],y[60000:]
pca = PCA()
pca.fit(X_train)
cumsum = np.cumsum(pca.explained_variance_ratio_)
d = np.argmax(cumsum >= 0.90) + 1
#Setup a figure 8 inches by 8 inches
fig = plt.figure(figsize=(8,8))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)
for i in range(100):
ax = fig.add_subplot(10, 10, i+1, xticks=[], yticks=[])
ax.imshow(X_train[i].reshape(28,28), cmap=plt.cm.bone, interpolation='nearest')
plt.show()
【问题讨论】:
-
“给我一个错误”对可能的受访者没有帮助。什么错误?请查看如何创建minimal reproducible example(并修复您的代码缩进)。
标签: python matplotlib scikit-learn mnist