Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Visualization | Recognizing Handwritten Digits
Recognizing Handwritten Digits

book
Visualization

Our dataset consists of various rows, each depicting pixel values on a grey scale ranging from 0 to 255. Let's display a few of these images.

Завдання

Swipe to start coding

  1. Extract the feature data (images) from the MNIST dataset and store it in variable X.

  2. Loop through the first 7 images in the dataset and visualize each image using seaborn's heatmap function. Also you need to reshape each image to a 2D array of 28x28 pixels.

Рішення

import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

# Extract the feature data (images) from the MNIST dataset
X = mnist['data']

# Create a subplot of 1 row and 7 columns
f, ax = plt.subplots(1, 7, figsize=(13, 2))

# Loop through the first 7 images in the dataset
for n in range(7):
# Use seaborn's heatmap function to visualize each image
sns.heatmap(X[n].reshape(28, 28), cbar=False, cmap='gray_r', ax=ax[n])

Mark tasks as Completed
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
AVAILABLE TO ULTIMATE ONLY
some-alt