download_mnist: Download MNIST

Description Usage Arguments Format Details Value Note Examples

View source: R/mnist.R

Description

Download MNIST database of handwritten digits.

Usage

1
download_mnist(base_url = mnist_url, verbose = FALSE)

Arguments

base_url

Base URL that the MNIST files are located at.

verbose

If TRUE, then download progress will be logged as a message.

Format

A data frame with 785 variables:

px1, px2, px3 ... px784

Integer pixel value, from 0 (white) to 255 (black).

Label

The digit represented by the image, in the range 0-9.

Pixels are organized row-wise. The Label variable is stored as a factor.

There are 70,000 digits in the data set. The first 60,000 are the training set, as found in the train-images-idx3-ubyte.gz file. The remaining 10,000 are the test set, from the t10k-images-idx3-ubyte.gz file.

For more information see http://yann.lecun.com/exdb/mnist.

Details

Downloads the image and label files for the training and test datasets from http://yann.lecun.com/exdb/mnist and converts them to a data frame.

Value

Data frame containing the MNIST digits.

Note

Originally based on a function by Brendan O'Connor.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Not run: 
# download the MNIST data set
mnist <- download_mnist()

# first 60,000 instances are the training set
mnist_train <- head(mnist, 60000)
# the remaining 10,000 are the test set
mnist_test <- tail(mnist, 10000)

# PCA on 1000 random training examples
mnist_r1000 <- mnist_train[sample(nrow(mnist_train), 1000), ]
pca <- princomp(mnist_r1000[, 1:784], scores = TRUE)
# plot the scores of the first two components
plot(pca$scores[, 1:2], type = 'n')
text(pca$scores[, 1:2], labels = mnist_r1000$Label,
     col = rainbow(length(levels(mnist_r1000$Label)))[mnist_r1000$Label])

## End(Not run)

jlmelville/mnist documentation built on May 19, 2019, 12:47 p.m.