Learn R Programming

dslabs (version 0.7.1)

read_mnist: Download and read the mnist dataset

Description

This function downloads the mnist training and test data from http://yann.lecun.com/exdb/mnist/

Usage

read_mnist()

Arguments

Value

A list with two components: train and test. Each of these is a list with two components: images and labels. The images component is a matrix with each column representing one of the 28*28 = 784 pixels. The values are integers between 0 and 255 representing grey scale. The labels components is a vector representing the digit shown in the image.

Note that the data is over 200MB, so the download may take several seconds depending on internet speed.

References

Y. LeCun, L. Bottou, Y. Bengio, and P. Haffner. "Gradient-based learning applied to document recognition." Proceedings of the IEEE, 86(11):2278-2324, November 1998.

Examples

Run this code
# NOT RUN {
# this can take several seconds, depending on internet speed.
# }
# NOT RUN {
mnist <- read_mnist()
i <- 5
image(1:28, 1:28, matrix(mnist$test$images[i,], nrow=28)[ , 28:1], 
    col = gray(seq(0, 1, 0.05)), xlab = "", ylab="")
## the labels for this image is: 
mnist$test$labels[i]
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab