caret-machine-learning icon indicating copy to clipboard operation
caret-machine-learning copied to clipboard

caret and rborist hard crash

Open tobigithub opened this issue 9 years ago • 0 comments

Hard crash under windows and R3.3.1

require(caret)
require(mboost)
require(gbm)
require(randomForest)

# load iris set
data(iris) 
dim(iris) 

# works not "ordinalNet" extremely slow
m <- c("rf" ,"gbm", "Rborist")
#, "ordinalNet", "chaid")

# load X and Y (this will be transferred to to train function)
X = iris[,1:3]   
Y = iris$Species


# this setup actually calls the caret::train function, in order to provide
# minimal error handling this type of construct is needed.
trainCall <- function(i) 
    {
         cat("----------------------------------------------------","\n");
         set.seed(123); cat(i," <- loaded\n");
         return(tryCatch(
                t2 <- train(y=Y, x=X, (i), trControl = trainControl(method = "cv")),
                error=function(e) NULL))
    }

# use lapply/loop to run everything, required for try/catch error function to work
t2 <- lapply(m, trainCall)

#remove NULL values, we only allow succesful methods, provenance is deleted.
t2 <- t2[!sapply(t2, is.null)]

# this setup extracts the results with minimal error handling 
# TrainKappa can be sometimes zero, but Accuracy SD can be still available
# see Kappa value http://epiville.ccnmtl.columbia.edu/popup/how_to_calculate_kappa.html
printCall <- function(i) 
    {
         return(tryCatch(
            {
             cat(sprintf("%-22s",(m[i])))
         cat(round(getTrainPerf(t2[[i]])$TrainAccuracy,4),"\t")
         cat(round(getTrainPerf(t2[[i]])$TrainKappa,4),"\t")
         cat(t2[[i]]$times$everything[3],"\n")},
             error=function(e) NULL))
    }

r2 <- lapply(1:length(t2), printCall)



tobigithub avatar Jul 09 '16 07:07 tobigithub