Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read MNIST database in R?

I'm currently working on a case study for which I need to work on the MNIST database.
The files in this site are said to be in IDX file format. I tried to take a look at these files using basic text editors like notepad and wordpad, but no luck there.
Expecting that they would be in the high endian format, I tried the following:

to.read = file("t10k-images.idx3-ubyte", "rb")
readBin(to.read, integer(), n=100, endian = "high")

I got some numbers as output, but none of them made any sense to me.

Can anyone please explain how to read the MNIST database files in R and how to interpret those numbers? Thanks.

like image 360
StrikeR Avatar asked Feb 03 '14 07:02

StrikeR


People also ask

How do I get a MNIST dataset in R?

To load the files in R you need to use the load function (e.g. load(".. \\MNIST\\test. Rdata") . This will create the matrices trainData and testData in the environment.

Is MNIST a real-world dataset?

Take Note. The MNIST dataset consists of 60,000 training examples and 10,000 examples in the test set. It's a good dataset for those who want to learn techniques and pattern recognition methods on real-world data without much effort in data-preprocessing.

What is MNIST dataset format?

The MNIST dataset is an acronym that stands for the Modified National Institute of Standards and Technology dataset. It is a dataset of 60,000 small square 28×28 pixel grayscale images of handwritten single digits between 0 and 9.


1 Answers

MNIST dataset is also available in the keras package.

library(keras)
mnist <- dataset_mnist()
x_train <- mnist$train$x
y_train <- mnist$train$y
x_test <- mnist$test$x
y_test <- mnist$test$y
like image 83
Imran Kocabiyik Avatar answered Oct 16 '22 20:10

Imran Kocabiyik