run_lightgbm: Run gradient boosting model with lightgbm

View source: R/counterfactual_model.R

run_lightgbmR Documentation

Run gradient boosting model with lightgbm

Description

This function trains a gradient boosting model (lightgbm) on the specified training dataset and makes predictions on the test dataset in a counterfactual scenario. The model uses meteorological variables and temporal features.

Usage

run_lightgbm(train, test, model_params, alpha, calc_shaps)

Arguments

train

Dataframe of train data as returned by the split_data_counterfactual() function.

test

Dataframe of test data as returned by the split_data_counterfactual() function.

model_params

list of hyperparameters to use in lgb.train call. See lightgbm:lgb.train() params argument for details.

alpha

Confidence level of the prediction interval between 0 and 1.

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.

Details

Note: Runs the gradient boosting model for individualised use with own data pipeline. Otherwise use run_counterfactual() to call this function.

Value

List with data frame of predictions and model

Examples


data(mock_env_data)
split_data <- list(
  train = mock_env_data[1:80, ],
  apply = mock_env_data[81:100, ]
)
params <- load_params()
variables <- c("day_julian", "weekday", "hour", params$meteo_variables)
res <- run_lightgbm(
  train = mock_env_data[1:80, ],
  test = mock_env_data[81:100, ], params$lightgbm, alpha = 0.9,
  calc_shaps = FALSE
)
prediction <- res$dt_predictions
model <- res$model


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