get_calibrated_prediction_regression: Calibration of predictions of regression model using...

View source: R/get_calibrated_prediction_regression.R

get_calibrated_prediction_regressionR Documentation

Calibration of predictions of regression model using conformal prediction

Description

get_calibrated_prediction_regression calibrates regression predictions using conformal prediction to a point prediction with prediction interval for each observation of the test data set.

Usage

get_calibrated_prediction_regression(
  y_cal_pred,
  y_cal,
  y_test_pred,
  significance_level
)

Arguments

y_cal_pred

Predictions of regression model for calibration set.

y_cal

True label of outcome variable for calibration set. Has to be in the same order as y_cal_pred.

y_test_pred

Predictions of test data set that should be calibrated.

significance_level

Level of uncertainty that should be reached by calibration, should be between 0 and 1.

Value

data frame with point prediction and lower and upper bound of prediction interval.

Author(s)

Lea Louisa Kronziel, M.Sc.

Examples

require(ranger)
require(timbR)
require(dplyr)

regr_data <- longley %>% data.frame()
# Train random forest with ranger
rf <- ranger(Employed ~ ., data = regr_data, num.trees = 10, importance = "permutation")

# Calculate pair-wise distances for all trees
rep_tree <- generate_tree(rf = rf, metric = "splitting variables", train_data = regr_data, dependent_varname = "Employed", importance.mode = TRUE, imp.num.var = 2)

# Get predictions
rep_tree_predictions <- predict(rep_tree, regr_data)$predictions

# Calibrated predictions
get_calibrated_prediction_regression(y_cal_pred = rep_tree_predictions, y_cal = regr_data$Employed, y_test_pred = rep_tree_predictions, significance_level = 0.05)


imbs-hl/timbR documentation built on April 17, 2025, 2:08 p.m.