Learn R Programming

superml (version 0.4.0)

GridSearchCV: Grid Search CV

Description

Grid search CV is used to train a machine learning model with multiple combinations of training hyper parameters and finds the best combination of parameters which optimizes the evaluation metric. It creates an exhaustive set of hyperparameter combinations and train model on each combination.

Usage

GridSearchCV

Format

R6Class object.

Usage

For usage details see Methods, Arguments and Examples sections.

gst = GridSearchTrainer$new(trainer, parameters, n_folds, scoring)
gst$fit(X, y)
gst$best_iteration(metric)

Methods

$new()

Initialises an instance of grid 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, could be either XGBTrainer, RFTrainer, NBTrainer etc.

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

Examples

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

Run the code above in your browser using DataLab