gpt4 book ai didi

r - 无法将 Adaboost 与 R 的插入符包一起使用

转载 作者:行者123 更新时间:2023-11-30 08:43:43 24 4
gpt4 key购买 nike

我正在使用 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)

最佳答案

我使用以下代码重现了您的问题:

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)

对我来说,“AdaBoost.M1”训练运行了大约十分钟,然后我决定停止它。然后我添加了一个如下指定的调整网格,并在一分钟内得到了结果。我建议您尝试以类似的方式调整代码:

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)

请告诉我这是否能解决您的问题。

关于r - 无法将 Adaboost 与 R 的插入符包一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43272384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com