| MLLearnerBase | R Documentation |
The MLLearnerBase class is used to construct a learner object that can be
used with the experiment classes from the mlexperiments package. It is
thought to serve as a class to inherit from when creating new learners.
The learner class exposes 4 methods that can be defined:
$fit A wrapper around the private function fun_fit, which needs to
be defined for every learner. The return value of this function is the
fitted model.
$predict A wrapper around the private function fun_predict,
which needs to be defined for every learner. The function must accept the
three arguments model, newdata, and ncores and is a wrapper around
the respective learner's predict-function. In order to allow the passing of
further arguments, the ellipsis (...) can be used. The function should
return the prediction results.
$cross_validation A wrapper around the private function
fun_optim_cv, which needs to be defined when hyperparameters should be
optimized with a grid search (required for use with
MLTuneParameters, and MLNestedCV).
$bayesian_scoring_function A wrapper around the private function
fun_bayesian_scoring_function, which needs to be defined when
hyperparameters should be optimized with a Bayesian process (required for
use with MLTuneParameters, and
MLNestedCV).
For further details please refer to the package's vignette.
cluster_exportA character vector defining the (internal)
functions that need to be exported to the parallelization cluster.
This is only required when performing a Bayesian hyperparameter
optimization. See also parallel::clusterExport().
metric_optimization_higher_betterA logical. Defines the direction
of the optimization metric used throughout the hyperparameter
optimization. This field is set automatically during the initialization
of the MLLearnerBase object. Its purpose is to make it accessible by
the evaluation functions from MLTuneParameters.
environmentThe environment in which to search for the functions
of the learner (default: -1L).
seedSeed for reproducible results.
new()Create a new MLLearnerBase object.
MLLearnerBase$new(metric_optimization_higher_better)
metric_optimization_higher_betterA logical. Defines the direction of the optimization metric used throughout the hyperparameter optimization.
A new MLLearnerBase R6 object.
MLLearnerBase$new(metric_optimization_higher_better = FALSE)
cross_validation()Perform a cross-validation with an MLLearnerBase.
MLLearnerBase$cross_validation(...)
...Arguments to be passed to the learner's cross-validation function.
A wrapper around the private function fun_optim_cv, which needs to be
defined when hyperparameters should be optimized with a grid search
(required for use with MLTuneParameters, and
MLNestedCV.
However, the function should be never executed directly but by the
respective experiment wrappers MLTuneParameters, and
MLNestedCV.
For further details please refer to the package's vignette.
The fitted model.
learner <- MLLearnerBase$new(metric_optimization_higher_better = FALSE)
\dontrun{
# This example cannot be run without further adaptions.
# The method `$cross_validation()` needs to be overwritten when
# inheriting from this class.
learner$cross_validation()
}
fit()Fit a MLLearnerBase object.
MLLearnerBase$fit(...)
...Arguments to be passed to the learner's fitting function.
A wrapper around the private function fun_fit, which needs to be
defined for every learner. The return value of this function is the
fitted model.
However, the function should be never executed directly but by the
respective experiment wrappers MLTuneParameters,
MLCrossValidation, and
MLNestedCV.
For further details please refer to the package's vignette.
The fitted model.
learner <- MLLearnerBase$new(metric_optimization_higher_better = FALSE)
\dontrun{
# This example cannot be run without further adaptions.
# The method `$fit()` needs to be overwritten when
# inheriting from this class.
learner$fit()
}
predict()Make predictions from a fitted MLLearnerBase object.
MLLearnerBase$predict(model, newdata, ncores = -1L, ...)
modelA fitted model of the learner (as returned by
MLLearnerBase$fit()).
newdataThe new data for which predictions should be made using
the model.
ncoresAn integer to specify the number of cores used for
parallelization (default: -1L).
...Further arguments to be passed to the learner's predict function.
A wrapper around the private function fun_predict, which needs to be
defined for every learner. The function must accept the three arguments
model, newdata, and ncores and is a wrapper around the respective
learner's predict-function. In order to allow the passing of further
arguments, the ellipsis (...) can be used. The function should
return the prediction results.
However, the function should be never executed directly but by the
respective experiment wrappers MLTuneParameters,
MLCrossValidation, and
MLNestedCV.
For further details please refer to the package's vignette.
The predictions for newdata.
learner <- MLLearnerBase$new(metric_optimization_higher_better = FALSE)
\dontrun{
# This example cannot be run without further adaptions.
# The method `$predict()` needs to be overwritten when
# inheriting from this class.
learner$fit()
learner$predict()
}
bayesian_scoring_function()Perform a Bayesian hyperparameter optimization with an MLLearnerBase.
MLLearnerBase$bayesian_scoring_function(...)
...Arguments to be passed to the learner's Bayesian scoring function.
A wrapper around the private function fun_bayesian_scoring_function,
which needs to be defined when hyperparameters should be optimized with
a Bayesian process (required for use with
MLTuneParameters, and MLNestedCV.
However, the function should be never executed directly but by the
respective experiment wrappers MLTuneParameters, and
MLNestedCV.
For further details please refer to the package's vignette.
The results of the Bayesian scoring.
learner <- MLLearnerBase$new(metric_optimization_higher_better = FALSE)
\dontrun{
# This example cannot be run without further adaptions.
# The method `$bayesian_scoring_function()` needs to be overwritten when
# inheriting from this class.
learner$bayesian_scoring_function()
}
clone()The objects of this class are cloneable with this method.
MLLearnerBase$clone(deep = FALSE)
deepWhether to make a deep clone.
MLTuneParameters, MLCrossValidation, and MLNestedCV
MLTuneParameters, MLCrossValidation, and MLNestedCV
MLTuneParameters, MLCrossValidation, and MLNestedCV
ParBayesianOptimization::bayesOpt(),
MLTuneParameters, and MLNestedCV
MLLearnerBase$new(metric_optimization_higher_better = FALSE)
## ------------------------------------------------
## Method `MLLearnerBase$new`
## ------------------------------------------------
MLLearnerBase$new(metric_optimization_higher_better = FALSE)
## ------------------------------------------------
## Method `MLLearnerBase$cross_validation`
## ------------------------------------------------
learner <- MLLearnerBase$new(metric_optimization_higher_better = FALSE)
## Not run:
# This example cannot be run without further adaptions.
# The method `$cross_validation()` needs to be overwritten when
# inheriting from this class.
learner$cross_validation()
## End(Not run)
## ------------------------------------------------
## Method `MLLearnerBase$fit`
## ------------------------------------------------
learner <- MLLearnerBase$new(metric_optimization_higher_better = FALSE)
## Not run:
# This example cannot be run without further adaptions.
# The method `$fit()` needs to be overwritten when
# inheriting from this class.
learner$fit()
## End(Not run)
## ------------------------------------------------
## Method `MLLearnerBase$predict`
## ------------------------------------------------
learner <- MLLearnerBase$new(metric_optimization_higher_better = FALSE)
## Not run:
# This example cannot be run without further adaptions.
# The method `$predict()` needs to be overwritten when
# inheriting from this class.
learner$fit()
learner$predict()
## End(Not run)
## ------------------------------------------------
## Method `MLLearnerBase$bayesian_scoring_function`
## ------------------------------------------------
learner <- MLLearnerBase$new(metric_optimization_higher_better = FALSE)
## Not run:
# This example cannot be run without further adaptions.
# The method `$bayesian_scoring_function()` needs to be overwritten when
# inheriting from this class.
learner$bayesian_scoring_function()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.