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) ...