Learn R Programming

⚠️There's a newer version (1.0.12) of this package.Take me there.

R Interface to AutoKeras

AutoKeras is an open source software library for automated machine learning (AutoML). It is developed by DATA Lab at Texas A&M University and community contributors. The ultimate goal of AutoML is to provide easily accessible deep learning tools to domain experts with limited data science or machine learning background. AutoKeras provides functions to automatically search for architecture and hyperparameters of deep learning models.

Check out the AutoKeras blogpost at the RStudio TensorFlow for R blog.

Dependencies

Installation

AutoKeras is currently only available as a GitHub package. To install it run the following from an R console:

if (!require("remotes")) {
  install.packages("remotes")
}
remotes::install_github("r-tensorflow/autokeras")

Then, use the install_autokeras() function to install TensorFlow:

library("autokeras")
install_autokeras()

Docker

autokeras R package has a configured Docker image.

Steps to run it:

From a bash console:

docker pull jcrodriguez1989/r-autokeras:1.0.0
docker run -it jcrodriguez1989/r-autokeras:1.0.0 /bin/bash

To run the docker image, and share the current folder (in home machine) to the /data path (in the docker machine), then do:

docker run -it -v ${PWD}:/data jcrodriguez1989/r-autokeras:1.0.0 /bin/bash
ls /data # once when the docker image is running

Examples

CIFAR-10 dataset

library("keras")

# Get CIFAR-10 dataset, but not preprocessing needed
cifar10 <- dataset_cifar10()
c(x_train, y_train) %<-% cifar10$train
c(x_test, y_test) %<-% cifar10$test
library("autokeras")

# Create an image classifier, and train 10 different models
clf <- model_image_classifier(
  directory = ".",
  name = "autokeras_cifar10",
  max_trials = 10
) %>%
  fit(x_train, y_train)
# And use it to evaluate, predict
clf %>% evaluate(x_test, y_test)
clf %>% predict(x_test[1:10, , , ])
# Get the best trained Keras model, to work with the keras R library
# Actually, exporting the model as a Keras model is not working as expected,
# check out the bug https://github.com/keras-team/autokeras/issues/929 .
(keras_model <- export_model(clf))
# Save the trained AutoKeras model
save_model(clf, "~/my_model.pkl")
# Later, the AutoKeras model can be loaded again with:
my_model <- load_model("~/my_model.pkl")

IMDb dataset

library("keras")

# Get IMDb dataset
imdb <- dataset_imdb(num_words = 1000)
c(x_train, y_train) %<-% imdb$train
c(x_test, y_test) %<-% imdb$test

# AutoKeras procceses each text data point as a character vector,
# i.e., x_train[[1]] "<START> this film was just brilliant casting..",
# so we need to transform the dataset.
word_index <- dataset_imdb_word_index()
word_index <- c(
  "<PAD>", "<START>", "<UNK>", "<UNUSED>",
  names(word_index)[order(unlist(word_index))]
)
x_train <- lapply(x_train, function(x) {
  paste(word_index[x + 1], collapse = " ")
})
x_test <- lapply(x_test, function(x) {
  paste(word_index[x + 1], collapse = " ")
})

x_train <- array(unlist(x_train))
x_test <- array(unlist(x_test))
y_train <- matrix(y_train, ncol = 1)
y_test <- matrix(y_test, ncol = 1)
library("autokeras")

# Create a text classifier, and train 10 different models
clf <- model_text_classifier(max_trials = 10) %>%
  fit(x_train, y_train)
# And use it to evaluate, predict
clf %>% evaluate(x_test, y_test)
clf %>% predict(x_test[1:10])
# Get the best trained Keras model, to work with the keras R library
export_model(clf)

Copy Link

Version

Install

install.packages('autokeras')

Monthly Downloads

203

Version

1.0.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Juan Cruz Rodriguez

Last Published

February 20th, 2020

Functions in autokeras (1.0.1)

install_autokeras

Install Autokeras, Keras, and the Tensorflow Backend
evaluate

Evaluate a Model
save_model

Save Model
model_structured_data_regressor

AutoKeras Structured Data Regressor Model
export_model

Export Model
model_image_regressor

AutoKeras Image Regressor Model
model_structured_data_classifier

AutoKeras Structured Data Classifier Model
predict

Model Predictions
model_text_regressor

AutoKeras Text Regressor Model
AutokerasModel-class

Autokeras Model Class Representation
model_text_classifier

AutoKeras Text Classifier Model
autokeras-package

R Interface to AutoKeras
load_model

Load Model
model_image_classifier

AutoKeras Image Classifier Model
fit

Search for the Best Model and Hyperparameters