The MNIST dataset is included in keras and can be accessed using the dataset_mnist() function:
- Let's load the data into the R environment:
mnist <- dataset_mnist()x_train <- mnist$train$xy_train <- mnist$train$yx_test <- mnist$test$xy_test <- mnist$test$y
- Our training data is of the form (images, width, height). Due to this, we'll convert the data into a one-dimensional array and rescale it:
# Reshaping the datax_train <- array_reshape(x_train , c(nrow(x_train),784))x_test <- array_reshape(x_test , c(nrow(x_test),784))# Rescaling the datax_train <- x_train/255x_test <- x_test/255
- Our target data is an integer vector and contains values from 0 to 9. We need to one-hot encode our target variable in order to convert it into ...