Title: Loading scikit-learn's Digits Dataset
Slug: loading_scikit-learns_digits-dataset
Summary: Loading the built-in digits datasets of scikit-learn.
Date: 2016-08-31 12:00
Category: Machine Learning
Tags: Basics
Authors: Chris Albon
In [1]:
# Load libraries
from sklearn import datasets
import matplotlib.pyplot as plt
In [2]:
# Load digits dataset
digits = datasets.load_digits()
# Create feature matrix
X = digits.data
# Create target vector
y = digits.target
# View the first observation's feature values
X[0]
Out[2]:
The observation's feature values are presented as a vector. However, by using the images
method we can load the the same feature values as a matrix and then visualize the actual handwritten character:
In [3]:
# View the first observation's feature values as a matrix
digits.images[0]
Out[3]:
In [4]:
# Visualize the first observation's feature values as an image
plt.gray()
plt.matshow(digits.images[0])
plt.show()