RandomSearchCV: Random Search CV

RandomSearchCVR Documentation

Random Search CV

Description

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

Public 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")
rst$best_iteration()

superml documentation built on Nov. 14, 2022, 9:05 a.m.