我正在使用R的插入符号包来实现adaboost技术。但是我在执行它时遇到错误。
> 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,]
当我用插入符号
实现gbm时没有问题#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)
但即使我保持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)
答案 0 :(得分:2)
我使用以下代码重现您的问题:
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)
对我来说,&#34; AdaBoost.M1&#34;在我决定停止训练之前,训练跑了大约十分钟。然后我添加了一个如下所示的调整网格,并在一分钟内得到了一个结果。我建议您尝试以类似的方式调整代码:
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)
如果这可以解决您的问题,请告诉我。