简体   繁体   中英

unable to use Adaboost with R's caret package

I'm using R's caret package for implementing adaboost technique. But I'm getting an error while executing it.

> str(my_data)
'data.frame':   3885 obs. of  10 variables:
 $ Date    : Factor w/ 12 levels "0","1","2","3",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ JAPAN   : int  0 1 0 0 0 0 1 1 0 1 ...
 $ HONGKONG: int  0 1 0 1 0 0 0 1 1 1 ...
 $ CHINA   : int  1 0 1 1 1 1 0 1 1 0 ...
 $ INDIA   : int  0 0 0 1 0 0 1 1 0 1 ...
 $ GERMANY : int  0 1 1 0 1 1 0 0 0 1 ...
 $ FRANCE  : int  0 1 1 0 1 1 0 0 0 1 ...
 $ EURO    : int  0 1 1 0 1 1 0 0 0 1 ...
 $ LONDON  : int  0 1 1 0 1 1 0 0 0 1 ...
 $ DOWJONES: int  0 1 0 1 1 1 0 0 0 1 ...
> Train=my_data[1:3600,]            #2015
> test=my_data[3601:3860,]

There is no problem when I'm implementing gbm with caret

#1 gradient boost
set.seed(995)
fitControl_1 <- trainControl( method = "repeatedcv", number = 4, repeats = 5)
gbm_model<- train(factor(INDIA)~Date+JAPAN+HONGKONG+CHINA+GERMANY+FRANCE+EURO+LONDON+DOWJONES,data=Train, method = "gbm", trControl = fitControl_1,verbose=TRUE)
PREDICTION_GBM= predict(gbm_model,test)
solution <- data.frame(org_bse = test$INDIA, GBM = PREDICTION_GBM)

But I'm not getting the output even though I kept the verbose=TRUE

#2 Adaboost
set.seed(995)
fitControl_2 <- trainControl( method = "repeatedcv", number = 5, repeats = 5)
ada_model<- train(factor(INDIA)~Date+JAPAN+HONGKONG+CHINA+GERMANY+FRANCE+EURO+LONDON+DOWJONES,data=Train,method="AdaBoost.M1",trControl = fitControl_2,verbose=TRUE)
PREDICTION_ADA= predict(ada_model,test)
solution<-cbind(solution,ADA=PREDICTION_ADA)

I used the following code to reproduce your problem:

library(caret)
set.seed(995)

Train <- data.frame(
  cyl = as.factor(mtcars$cyl),
  vs = as.factor(mtcars$vs),
  am = as.factor(mtcars$am),
  gear = as.factor(mtcars$gear),
  carb = as.factor(mtcars$carb))

fitControl_2 <- trainControl(method = "repeatedcv", number = 2, repeats = 1)
ada_model<- train(
  cyl ~ vs + am + gear + carb,
  data = Train,
  method ="AdaBoost.M1",
  trControl = fitControl_2,
  verbose = TRUE)

For me, "AdaBoost.M1" training ran for about ten minutes before I decided to stop it. I then added a tuning grid as specified below, and got a result within a minute. I recommend you try to adjust your code in a similar fashion:

library(caret)
set.seed(995)

Train <- data.frame(
  cyl = as.factor(mtcars$cyl),
  vs = as.factor(mtcars$vs),
  am = as.factor(mtcars$am),
  gear = as.factor(mtcars$gear),
  carb = as.factor(mtcars$carb))


fitGrid_2 <- expand.grid(mfinal = (1:3)*3,         # This is new!
                         maxdepth = c(1, 3),       # ...and this
                         coeflearn = c("Breiman")) # ...and this

fitControl_2 <- trainControl(method = "repeatedcv", 
                             number = 2, 
                             repeats = 1)
ada_model <- train(
  cyl ~ vs + am + gear + carb,
  data = Train,
  method ="AdaBoost.M1",
  trControl = fitControl_2,
  tuneGrid = fitGrid_2, #and this is new, too!
  verbose = TRUE)

Let me know if this solves your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM