Skip to content

Data and modelling failures

Source: R/errors.R ยท Help: ?modelling_errors

Errors raised while loading data and fitting or using a model. All inherit from dataexcept_data_science_error; convergence_error() also inherits from dataexcept_model_training_error, so a handler for training failures catches non-convergence too.

Usage

data_loading_error(source, parent = NULL, call = NULL)

missing_data_error(feature, message = NULL, parent = NULL, call = NULL)

model_training_error(
  model_type,
  epoch = NULL,
  message = NULL,
  parent = NULL,
  call = NULL
)

convergence_error(
  model_type,
  iterations,
  message = NULL,
  parent = NULL,
  call = NULL
)

prediction_error(
  model_type,
  inputs = NULL,
  message = NULL,
  parent = NULL,
  call = NULL
)

Arguments

source
The file path or URL the data came from. A URL is redacted.
parent
The condition that caused this one, or NULL.
call
The call to report, or NULL.
feature
Name of the missing feature.
message
A message to use instead of the default.
model_type
The model, as a name such as "glm".
epoch
Optional iteration or epoch at which training failed.
iterations
Number of iterations run before giving up.
inputs
Optional snapshot of the inputs a prediction failed on. It is stored as given; the envelope renders a data frame or matrix as a short description rather than its contents.

Value

A condition inheriting from dataexcept_data_science_error.

Examples

fit_or_fail <- function(formula, data, maxit = 25) {
  fit <- suppressWarnings(glm(formula,
    family = binomial, data = data,
    control = glm.control(maxit = maxit)
  ))
  if (!fit$converged) {
    stop(convergence_error("glm", iterations = fit$iter))
  }
  fit
}

separated <- data.frame(y = c(0, 0, 1, 1), x = 1:4)
tryCatch(
  fit_or_fail(y ~ x, separated, maxit = 5),
  dataexcept_model_training_error = function(e) e$iterations
)

See also

Other dataexcept errors: data_engineering_errors, data_frame_errors, data_quality_errors, file_errors, job_errors, model_quality_errors, pipeline_errors, service_errors, validation_error()