Loading scikit-learn's MNIST Hand-Written Dataset
Goal¶
This post aims to introduce how to load MNIST (hand-written digit image) dataset using scikit-learn
Refernce
Library¶
In [11]:
from sklearn.datasets import load_digits
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
Load Dataset¶
In [2]:
mnist = load_digits()
In [3]:
type(mnist)
Out[3]:
In [4]:
mnist.keys()
Out[4]:
Data¶
In [5]:
pd.DataFrame(mnist.data).head()
Out[5]:
Target¶
In [6]:
pd.DataFrame(mnist.target).head()
Out[6]:
Images¶
This dataset comprises of 8 x 8 images.
In [13]:
plt.imshow(mnist.images[0]);
In [27]:
fig, axes = plt.subplots(2, 10, figsize=(16, 6))
for i in range(20):
axes[i//10, i %10].imshow(mnist.images[i], cmap='gray');
axes[i//10, i %10].axis('off')
axes[i//10, i %10].set_title(f"target: {mnist.target[i]}")
plt.tight_layout()
Comments
Comments powered by Disqus