bagg.default {TWIX} | R Documentation |
Predictions from TWIX's or Bagging Trees
Description
Prediction of a new observation based on multiple trees.
Usage
## Default S3 method:
bagg(object,newdata=NULL,sq=1:length(object$trees),
aggregation="weighted",...)
## S3 method for class 'TWIX':
bagg(object,...)
## S3 method for class 'bootTWIX':
bagg(object,...)
Arguments
object |
object of classes TWIX or bootTWIX . |
newdata |
a data frame of new observations. |
sq |
Integer vector indicating for which trees predictions are required. |
aggregation |
character string specifying how to aggregate. There are
two ways to aggregate the TWIX trees. One of them is the class majority voting
(aggregation="majority" ) and another method is the weighted aggregation
(aggregation="weighted" ). |
... |
additional arguments. |
See Also
TWIX
, predict.TWIX
, bootTWIX
Examples
library(ElemStatLearn)
data(SAheart)
### response variable must be a factor
SAheart$chd <- factor(SAheart$chd)
### test and train data
###
set.seed(1234)
icv <- sample(nrow(SAheart),nrow(SAheart)/3)
itr <- setdiff(1:nrow(SAheart),icv)
train <- SAheart[itr,]
test <- SAheart[icv,]
### TWIX Ensemble
M1 <- TWIX(chd~.,data=train,topN=c(4,3),topn.method="single")
### Bagging with greedy decision trees as base classifier
M2 <- bootTWIX(chd~.,data=train,nbagg=30)
### Bagging with the p-value adjusted classification trees as base classifier
M3 <- bootTWIX(chd~.,data=train,nbagg=30,splitf="p-adj",Devmin=0.01)
preda <- bagg(M1,test,sq=1:length(M1$trees),aggregation="majority")
predb <- bagg(M1,test,sq=1:length(M1$trees),aggregation="weighted")
pred1 <- predict(M2,test,sq=1:length(M2$trees))
pred2 <- predict(M3,test,sq=1:length(M3$trees))
###
### CCR's
sum(preda == test$chd)/nrow(test)
sum(predb == test$chd)/nrow(test)
sum(pred1 == test$chd)/nrow(test)
sum(pred2 == test$chd)/nrow(test)
[Package
TWIX version 0.2.6
Index]