Skip to content

How to plot MNIST image #3760

Answered by ChiaLingWeng
drozzy asked this question in Q&A
Discussion options

You must be logged in to vote

Use flatten transforms and window transforms as the link mentioned:

import altair as alt
import pandas as pd
import numpy as np
from sklearn.datasets import fetch_openml
pixel_values,targets = fetch_openml("mnist_784",version=1,return_X_y=True)

reshape to the proper dimension:

# get data slice --> here we get 2 image data
image_data = pixel_values[1:3]
pic = []
for i in range(len(image_data)):
    pic.append(image_data.iloc[i].values.reshape(28,28))

data = pd.DataFrame({
    'image': pic  # list of 2D arrays
})
alt.Chart(data).transform_window(
    index='count()'           # number each of the images
).transform_flatten(
    ['image']                 # extract rows from each image
).t…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by dangotbanned
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
4 participants
Converted from issue

This discussion was converted from issue #2073 on January 07, 2025 20:26.