View source: R/get_calibrated_prediction_regression.R
get_calibrated_prediction_regression | R Documentation |
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.
get_calibrated_prediction_regression(
y_cal_pred,
y_cal,
y_test_pred,
significance_level
)
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. |
data frame with point prediction and lower and upper bound of prediction interval. |
Lea Louisa Kronziel, M.Sc.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.