Evaluate the model performance of a model
performance.Rdperformance() fits the model(s) in x and calculates a performance table,
i.e. the same type of output as cv_performance().
The reported training error refers to the full model data, while test error is the error for
the data provided in the newdata argument.
Test error is NA if no newdata is specified.
Usage
performance(x, ...)
# S3 method for model
performance(
x,
newdata = NULL,
metric = NULL,
eval_weights = x$weights,
newweights = NULL,
na.rm = FALSE,
...
)
# S3 method for model_fm_xgb
performance(
x,
newdata = NULL,
metric = NULL,
eval_weights = x$weights,
newweights = NULL,
na.rm = FALSE,
...
)
# S3 method for default
performance(
x,
newdata = NULL,
metric = NULL,
eval_weights = x$weights,
newweights = NULL,
na.rm = FALSE,
...
)
# S3 method for multimodel
performance(
x,
newdata = NULL,
metric = NULL,
eval_weights = "default",
newweights = NULL,
na.rm = FALSE,
param = TRUE,
...
)
# S3 method for cv
performance(x, newdata = NULL, metric = x$metric[1], ...)Arguments
- x
A model, or other object.
- ...
Passed to the
metricfunction.- newdata
Additional data for out-of-sample evaluation
- metric
A metric (see
metrics), specified either as a character string (name of the metric function), or as a named list of length 1, as inlist(rmse = rmse).metric=NULLselects the default metric, seedefault_metric.- eval_weights, newweights
Evaluation weights for training and test data, respectively.
- na.rm
Logical: Whether NA values should be excluded from computations.
- param
Logical: Keep parameters from the parameter table in the output?
Value
performance() returns a performance table.
This is a param_table with additional class “performance”
having additional information in its attributes.
Methods
performance.model()is the core method.performance.default(x, ...)executesx %>% model %>% performance(...), wherexis a fitted model.performance.multimodel(x, ...)runsperformance.model()for the models included inxand combines the results in performance table withn_model(x)rows. It usesmetric = default_metric(x)by default.performance.cv()extracts the multimodel from the “cv” object and then appliesperformance.multimodel(), using the first cross-validated model's metric as defaultmetric.
Examples
even_ind <- seq(150)%%2 == 0
mylm <- lm(Sepal.Length ~., iris[even_ind, ]) # using half of the data to train
performance(mylm)
#> --- Performance table ---
#> Metric: rmse
#> train_rmse test_rmse
#> model 0.26229 NA
performance(mylm, newdata = iris[!even_ind, ]) # test set is complement of model data
#> --- Performance table ---
#> Metric: rmse
#> train_rmse test_rmse
#> model 0.26229 0.34786