predict.TWIX {TWIX}R Documentation

Predictions from a TWIX object

Description

The result is a data frame, whose rows are prediction values from appointed tree(s).

Usage

## S3 method for class 'TWIX':
predict(object,newdata,sq=1,ccr=FALSE,type="class", ...)

Arguments

object an object returned from TWIX function.
newdata data frame containing the new data(test data).
sq Integer vector indicating for which trees predictions are required.
ccr logical. If TRUE the result is a list of two components: a data frame with prediction values and correct classification rate of trees.
type character string indicating the type of predicted value returned. Either class predicted classes or prob estimated class probabilities are returned.
... additional arguments.

See Also

bagg, TWIX, plot.TWIX

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,]

    M1 <- TWIX(chd~.,data=train,topN=c(4,3),topn.method="single")

    ### classification 
    pred <- predict(M1,newdata=test,sq=1:2)
    pred

    ### for correct classification rate
    predict(M1,newdata=test,sq=1:2,ccr=TRUE)$CCR

    ### estimated class probabilities
    predict(M1,newdata=test,sq=1,type="prob")

[Package TWIX version 0.2.6 Index]