Change the default metric of a cv
object
set_metric.Rd
set_metric
is applied to an object x
of class “cv” including one or several
cross-validated models. It changes the default metric of all models in x
.
Usage
set_metric(x, ...)
# S3 method for cv
set_metric(x, metric = x$metric[1], eval_weights = "default", ...)
Arguments
- x
An object of class “cv”.
- ...
Passed to metric function.
- metric
A metric (see metrics).
- eval_weights
Evaluation weights; see the “Evaluation weights” in the “Details” section of
?modeltuner
."eval_weights=default
means “use fitting weights” while"eval_weights=NULL
means unweighted evaluation.
Details
Changing the metric is most useful when applied to models based on an iteratively fitted model (see ifm).
In this case, the evaluation log is recalculated for the new metric and
the preference criteria are evaluated based on this updated log.
These computations are only possible when the input “cv” object contains the
cross-validation model fits, which requires that it has been generated in a
call cv(..., keep_fits = TRUE)
.
Examples
m <- model(fm_xgb(Sepal.Length ~., iris), max_depth = 2,
label = "xgb_model")
cvm <- cv(m, keep_fits = TRUE) # keep_fits=TRUE is required here
cv_performance(cvm)
#> --- Performance table ---
#> Metric: rmse
#> train_rmse test_rmse iteration time_cv
#> xgb_model 0.23594 0.31776 29 0.112
# change the metric
cvm_medae <- set_metric(cvm, "medae")
cv_performance(cvm_medae)
#> --- Performance table ---
#> Metric: medae
#> train_medae test_medae iteration time_cv
#> xgb_model 0.20527 0.24492 11 0.112