Hyperparameter tuning using random search scheme.

Details

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.

Super class

superml::GridSearchCV -> RandomSearchTrainer

Public fields

n_iter

number of models to be trained

Methods

Inherited methods


Method new()

Usage

RandomSearchCV$new(
  trainer = NA,
  parameters = NA,
  n_folds = NA,
  scoring = NA,
  n_iter = NA
)

Arguments

trainer

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

parameters

list, list containing parameters

n_folds

integer, number of folds to use to split the train data

scoring

character, 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

integer, number of models to be trained

Details

Create a new `RandomSearchTrainer` object.

Returns

A `RandomSearchTrainer` object.

Examples

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)


Method fit()

Usage

RandomSearchCV$fit(X, y)

Arguments

X

data.frame containing features

y

character, name of target variable

Details

Train the model on given hyperparameters

Returns

NULL, tunes hyperparameters and stores the result in memory

Examples

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


Method clone()

The objects of this class are cloneable with this method.

Usage

RandomSearchCV$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `RandomSearchCV$new`
## ------------------------------------------------

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)

## ------------------------------------------------
## Method `RandomSearchCV$fit`
## ------------------------------------------------

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")
#> [1] "In total, 4 models will be trained"
rst$best_iteration()
#> $n_estimators
#> [1] 500
#> 
#> $max_depth
#> [1] 10
#> 
#> $accuracy_avg
#> [1] 0.96
#> 
#> $accuracy_sd
#> [1] 0.02
#> 
#> $auc_avg
#> [1] NaN
#> 
#> $auc_sd
#> [1] NA
#>