Model evaluation and training failures¶
Source: R/errors-quality.R ยท Help: ?model_quality_errors
Errors about a model's quality and the process that produces it: a metric
that could not be computed, cross-validation that failed, an invalid
hyperparameter, training that ran out of time, a model that fits its
training data too closely or not closely enough, a model that could not be
saved, and a computation that exceeded its resources. All inherit from
dataexcept_data_science_error; training_timeout_error() also inherits from
dataexcept_model_training_error, so a handler for training failures
catches it.
Usage¶
model_evaluation_error(
metric,
value,
message = NULL,
parent = NULL,
call = NULL
)
cross_validation_error(folds, details = NULL, parent = NULL, call = NULL)
hyperparameter_error(param, value, message = NULL, parent = NULL, call = NULL)
training_timeout_error(model_type, timeout, parent = NULL, call = NULL)
model_serialization_error(path, parent = NULL, call = NULL)
overfitting_error(train_metric, val_metric, parent = NULL, call = NULL)
underfitting_error(train_metric, threshold, parent = NULL, call = NULL)
resource_limit_error(resource, limit, parent = NULL, call = NULL)
Arguments¶
metric- Name of the metric.
value- For
model_evaluation_error(), the value computed, oftenNaN. Forhyperparameter_error(), the value rejected, stored as given. message- A message to use instead of the default.
parent- The condition that caused this one, or
NULL. call- The call to report, or
NULL. folds- Number of folds.
details- Optional detail, appended to the message.
param- Name of the hyperparameter.
model_type- The model, as a name such as
"xgboost". timeout- The time limit that was exceeded, in seconds.
path- The file the model was being written to. A URL is redacted.
train_metric- The metric on the training data.
val_metric- The metric on the validation data.
threshold- The smallest training metric accepted.
resource- The resource that ran out, such as
"memory". limit- The limit that was exceeded, stored as given.
Value¶
A condition inheriting from dataexcept_data_science_error.
Examples¶
check_fit <- function(train_auc, val_auc, tolerance = 0.1) {
if (train_auc - val_auc > tolerance) stop(overfitting_error(train_auc, val_auc))
invisible(TRUE)
}
tryCatch(check_fit(0.99, 0.71), dataexcept_data_science_error = conditionMessage)
# A metric that could not be computed is usually NaN.
err <- model_evaluation_error("auc", NaN)
conditionMessage(err)
# The cause of a failed save is kept, and its message appended.
saved <- tryCatch(
saveRDS(lm(dist ~ speed, cars), file.path(tempfile(), "model.rds")),
warning = function(w) model_serialization_error("model.rds", parent = w)
)
conditionMessage(saved)
See also¶
Other dataexcept errors:
data_engineering_errors,
data_frame_errors,
data_quality_errors,
file_errors,
job_errors,
modelling_errors,
pipeline_errors,
service_errors,
validation_error()