| RandomSearchCV {superml} | R 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_iternumber 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
trainersuperml trainer object, must be either XGBTrainer, LMTrainer, RFTrainer, NBTrainer
parameterslist, list containing parameters
n_foldsinteger, number of folds to use to split the train data
scoringcharacter, 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_iterinteger, 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
Xdata.frame containing features
ycharacter, 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
deepWhether 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()