Loading a small dataset
Why it matters In Module 3 you will teach a network to read handwritten digits. Here you meet the data first.
scikit-learn ships a small set of 1,797 handwritten digits, each an 8 by 8 grid of brightness values from 0 to 16, with a label 0 to 9.
from sklearn.datasets import load_digits
d = load_digits()
d.images.shape # (1797, 8, 8)
d.target[:5] # the labels of the first five
Before training on any dataset, count how many examples each class has. If one digit had ten times more examples, a lazy model could score well by always guessing it.
Class: one of the answers a classifier can give, here the digits 0 to 9.
Recap Look at the shapes and count the classes before anything else.
Words and symbols in this lesson
- array
- a NumPy block of numbers, all the same type, that does maths on every item at once
- shape
- the size of an array along each direction, for example (32, 64) is 32 rows of 64
Load the digits. Set n_images to the number of images, pixels_per_image to the number of pixels in one image, and class_counts to an array of 10 counts (how many of each digit). np.bincount counts whole numbers for you.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.