MNIST 手写数据集介绍
1、数据集介绍
- MNIST数据集是机器学习领域中非常经典的一个数据集,最简单的方法就是使用如下代码直接加载:
import tensorflow as tf
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.mnist.load_data()
print(X_train.shape, y_train.shape)
print(X_test.shape, y_test.shape)
- 可以看出数据集由60000个训练样本和10000个测试样本组成
- 每个样本都是一张28 * 28像素的灰度手写数字图片
- 每个像素点是一个0-255的整数
2、打印第一个手写图片
import matplotlib.pyplot as plt
plt.figure()
plt.imshow(X_train[0])
plt.colorbar()
plt.grid(False)
plt.show()
![ty8ZGV.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMS5heDF4LmNvbS8yMDIwLzA2LzA2L3R5OFpHVi5wbmc?x-oss-process=image/format,png)
3、打印前25张手写数字
X_train = X_train / 255.0
X_test = X_test / 255.0
class_names = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
plt.figure(figsize=(10,10))
for i in range(25):
plt.subplot(5,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(X_train[i], cmap=plt.cm.binary)
plt.xlabel(class_names[y_train[i]])
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200609192143692.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L25vdmVtYmVyX2Nob3Bpbg==,size_16,color_FFFFFF,t_70#pic_center)