Learn R Programming

superml (version 0.4.0)

RandomSearchCV: Random Search CV

Description

Given a set of hyper parameters, random search trainer provides a faster way of hyper parameter tuning. Here, the number of models to be trained can be defined by the user.

Usage

RandomSearchCV

Format

R6Class object.

Usage

For usage details see Methods, Arguments and Examples sections.

rst = RandomSearchCV$new(trainer, parameters, n_folds, scoring, n_iter)
rst$fit(X_train, "target")
rst$best_iteration(metric)

Methods

$new()

Initialises an instance of random search cv

$fit()

fit model to an input train data and trains the model.

$best_iteration()

returns best iteration based on a given metric. By default, uses the first scoring metric

Arguments

trainer

superml trainer object, must be either XGBTrainer, LMTrainer, RFTrainer, NBTrainer

parameters

list containing parameters

n_folds

number of folds to use to split the train data

scoring

scoring metric used to evaluate the best model, multiple values can be provided. currently supports: auc, accuracy, mse, rmse, logloss, mae, f1, precision, recall

n_iter

number of models to be trained

Examples

Run this code
# NOT RUN {
rf <- RFTrainer$new()
rst <-RandomSearchCV$new(trainer = rf,
                            parameters = list(n_estimators = c(100,500),
                            max_depth = c(5,2,10,14)),
                            n_folds = 3,
                            scoring = c('accuracy','auc'),
                            n_iter = 4)
data("iris")
rst$fit(iris, "Species")
rst$best_iteration()
# }

Run the code above in your browser using DataLab