Learn R Programming

ubair (version 1.1.1)

retrend_predictions: 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)

Value

Retrended dataframe with same structure as dt_predictions

which is returned by any of the run_model() functions.

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.

Examples

Run this code
# \donttest{
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)
# }

Run the code above in your browser using DataLab