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
-
Extract the feature data (images) from the MNIST dataset and store it in variable
X
. -
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.
Рішення
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат