run_counterfactual: Full counterfactual simulation run

View source: R/counterfactual_model.R

run_counterfactualR Documentation

Full counterfactual simulation run

Description

Chains detrending, training of a selected model, prediction and retrending together for ease of use. See documentation of individual functions for details.

Usage

run_counterfactual(
  split_data,
  params,
  detrending_function = "none",
  model_type = "rf",
  alpha = 0.9,
  log_transform = FALSE,
  calc_shaps = FALSE
)

Arguments

split_data

List of two named dataframes called train and apply

params

A list of parameters that define the following:

meteo_variables

A character vector specifying the names of the meteorological variables used as inputs.

model

A list of hyperparameters for training the chosen model. Name of this list and its parameters depend on the chosen models. See run_dynamic_regression(), run_lightgbm(), run_rf() and run_fnn() functions for details

detrending_function

String which defines type of trend to remove. Options are "linear","quadratic", "exponential", "spline", "none". See detrend() and retrend_predictions() for details.

model_type

String to decide which model to use. Current options random forest "rf", gradient boosted decision trees "lightgbm", "dynamic_regression" and feedforward neural network "fnn"

alpha

Confidence level of the prediction interval between 0 and 1.

log_transform

If TRUE, uses log transformation during detrending and retrending. For details see detrend() documentation

calc_shaps

Boolean value. If TRUE, calculate SHAP values for the method used and format them so they can be visualised with shapviz:sv_importance() and shapviz:sv_dependence(). The SHAP values are generated for a subset (or all, depending on the size of the dataset) of the test data.

Value

Data frame of predictions, model and importance

Examples

data(mock_env_data)
split_data <- list(
  train = mock_env_data[1:80, ],
  apply = mock_env_data[81:100, ]
)
params <- load_params()
res <- run_counterfactual(split_data, params, detrending_function = "linear")
prediction <- res$retrended_predictions
random_forest_model <- res$model

ubair documentation built on April 12, 2025, 2:12 a.m.