retrend_predictions: Restors the trend in the prediction

View source: R/data_preprocessing.R

retrend_predictionsR Documentation

Restors the trend in the prediction

Description

Takes a dataframe of predictions as returned by any of the 'run_model' functions and restores a trend which was previously removed via detrend(). This is necessary for the predictions and the true values to have the same units. The function is basically the inverse function to detrend() and should only be used in combination with it.

Usage

retrend_predictions(dt_predictions, trend, log_transform = FALSE)

Arguments

dt_predictions

Dataframe of predictions with columns value, prediction, prediction_lower, prediction_upper

trend

lm object generated by detrend()

log_transform

Returns values to solution space, if they have been log transformed during detrending. Use only in combination with log_transform parameter in detrend function.

Value

Retrended dataframe with same structure as dt_predictions which is returned by any of the run_model() functions.

Examples


data(mock_env_data)
split_data <- list(
  train = mock_env_data[1:80, ],
  apply = mock_env_data[81:100, ]
)
params <- load_params()
detrended_list <- detrend(split_data,
  mode = "linear"
)
trend <- detrended_list$model
detrended_train <- detrended_list$train
detrended_apply <- detrended_list$apply
result <- run_lightgbm(
  train = detrended_train,
  test = detrended_apply,
  model_params = params$lightgbm,
  alpha = 0.9,
  calc_shaps = FALSE
)
retrended_predictions <- retrend_predictions(result$dt_predictions, trend)


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