O'Reilly logo

R Deep Learning Projects by Pablo Maldonado, Yuxi Liu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Outlier detection in MNIST

Let's look again at the outlier detection problem in MNIST. As before, let's say that the digit 0 is our outlier this time, and we would like to be able to detect it. 

We go as before, reading and preprocessing the data:

library(keras)# Switch to the 1-based indexing from Roptions(tensorflow.one_based_extract = FALSE)K <- keras::backend()mnist <- dataset_mnist()X_train <- mnist$train$xy_train <- mnist$train$yX_test <- mnist$test$xy_test <- mnist$test$y## Exclude "0" from the training set. "0" will be the outlieroutlier_idxs <- which(y_train!=0, arr.ind = T)X_train <- X_train[outlier_idxs,,]y_test <- sapply(y_test, function(x){ ifelse(x==0,"outlier","normal")})# reshapedim(X_train) <- c(nrow(X_train), 784)dim(X_test) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required