Learn R Programming

itree (version 0.1)

getOOBLoss: Gets OOB Loss for each observation in a passed data frame.

Description

Uses bootstrap sampling to get average loss for each observation. We do this by averaging out-of-bag loss over a number of runs for each data point. Each in-sample tree is fit using the same settings as model_tree.obj.

Usage

getOOBLoss(model_tree.obj,data,nboot=100,
		sampleFcn = function(idx_vec){sample(idx_vec,replace=TRUE)},
		minsplit, minbucket,lossfcn)

Arguments

Value

A list with elements: bagpred = Average predictions for all N observations over all nboot runs. For classification it is the most common class. holdout.predictions = An N x nboot matrix with holdout predictions for each run along the columns. If observation i is in the learning sample for run j, then holdout.predicitions[i,j] is NA. avgOOBloss = N x 1 vector of average OOB loss.

Examples

Run this code
require(mlbench); data(BostonHousing)
#fit a tree:
cart <- itree(medv~.,BostonHousing,minsplit=25,minbucket=25,cp=0)

#generate theta-hat values by computing average out-of-bag loss:
theta_hats <- getOOBLoss(model_tree.obj=cart.bh,data=bh,nboot=100)

# Then for each leaf we estimate local risk by the mean in-node theta-hat.
lre <- estNodeRisk(tree.obj=cart.bh,est_observation_loss=theta_hats$avgOOBloss)

# to add the lre to the plot:
plot(cart.bh, do_node_re= TRUE, uniform=TRUE)
text(cart.bh, est_node_risk = lre)

Run the code above in your browser using DataLab