bartMachine (version 1.2.3)

bart_predict_for_test_data: Predict for Test Data with Known Outcomes

Description

Utility wrapper function for computing out-of-sample metrics for a BART model when the test set outcomes are known.

Usage

bart_predict_for_test_data(bart_machine, Xtest, ytest, prob_rule_class = NULL)

Arguments

bart_machine
An object of class ``bartMachine''.
Xtest
Data frame for test data containing rows at which predictions are to be made. Colnames should match that of the training data.
ytest
Actual outcomes for test data.
prob_rule_class
Threshold for classification.

Value

  • For regression models, a list with the following components is returned:
  • y_hatPredictions (as posterior means) for the test observations.
  • L1_errL1 error for predictions.
  • L2_errL2 error for predictions.
  • rmseRMSE for predictions.
  • For classification models, a list with the following components is returned:
  • y_hatClass predictions for the test observations.
  • p_hatProbability estimates for the test observations.
  • confusion_matrixA confusion matrix for the test observations.

See Also

predict

Examples

Run this code
#generate Friedman data
set.seed(11)
n  = 250 
p = 5
X = data.frame(matrix(runif(n * p), ncol = p))
y = 10 * sin(pi* X[ ,1] * X[,2]) +20 * (X[,3] -.5)^2 + 10 * X[ ,4] + 5 * X[,5] + rnorm(n)

##split into train and test
train_X = X[1 : 200, ]
test_X = X[201 : 250, ]
train_y = y[1 : 200]
test_y = y[201 : 250]

##build BART regression model
bart_machine = bartMachine(train_X, train_y)

#explore performance on test data
oos_perf = bart_predict_for_test_data(bart_machine, test_X, test_y)
print(oos_perf$rmse)

Run the code above in your browser using DataLab