View source: R/get_calibrated_prediction_regression_mondrian.R
get_calibrated_prediction_regression_mondrian | R Documentation |
get_calibrated_prediction_regression_mondrian
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_mondrian(
y_cal_pred,
y_cal,
y_test_pred,
significance_level,
tree,
cal_data,
test_data,
dependent_varname,
show_node_id = FALSE
)
y_cal_pred |
Predictions of decision tree 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. |
tree |
Tree whose predictions are to be calibrated, tree should be an object of class |
cal_data |
Data frame with calibration data (should contain same variables as train data). |
test_data |
Data frame with test data (should contain same variables as train data). |
dependent_varname |
Name of the dependent variable used to create the tree. |
show_node_id |
If true the ID of the terminal nodes of each prediction is returned as column in returned data frame. |
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_mondrian(y_cal_pred = rep_tree_predictions, y_cal = regr_data$Employed,
y_test_pred = rep_tree_predictions, significance_level = 0.05,
tree = rep_tree, cal_data = regr_data, test_data = regr_data,
dependent_varname = "Employed")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.