Examples for 'rpart::xpred.rpart'


Return Cross-Validated Predictions

Aliases: xpred.rpart

Keywords: tree

### ** Examples

fit <- rpart(Mileage ~ Weight, car.test.frame)
xmat <- xpred.rpart(fit)
xerr <- (xmat - car.test.frame$Mileage)^2
apply(xerr, 2, sum)   # cross-validated error estimate
0.79767456 0.28300396 0.04154257 0.01132626 
 1388.8498   654.4740   477.5976   485.9340 
# approx same result as rel. error from printcp(fit)
apply(xerr, 2, sum)/var(car.test.frame$Mileage)
0.79767456 0.28300396 0.04154257 0.01132626 
  60.49250   28.50616   20.80216   21.16526 
printcp(fit)
Regression tree:
rpart(formula = Mileage ~ Weight, data = car.test.frame)

Variables actually used in tree construction:
[1] Weight

Root node error: 1354.6/60 = 22.576

n= 60 

        CP nsplit rel error  xerror     xstd
1 0.595349      0   1.00000 1.05450 0.181398
2 0.134528      1   0.40465 0.57926 0.104050
3 0.012828      2   0.27012 0.42769 0.080225
4 0.010000      3   0.25729 0.41948 0.072499

[Package rpart version 4.1.19 Index]