0

私は R で Ensemble メソッドを使用しようとしており、BostonHousing2データセットでキャレット モデルのアンサンブルを試していました。貪欲なアンサンブルと線形アンサンブルをセットアップしているときに、エラーが発生します。コードは次のとおりです。

library(caret)
library(caretEnsemble)
library(mlbench)
data(BostonHousing2)
X <- model.matrix(cmedv~crim+zn+indus+chas+nox+rm+age+dis+
                rad+tax+ptratio+b+lstat+lat+lon, BostonHousing2)[,-1]
X <- data.frame(X)
Y <- BostonHousing2$cmedv
train <- runif(nrow(X)) <= 0.7
folds=5
repeats=1
myControl <- trainControl(method='cv', number=folds, repeats=repeats, returnResamp='none', 
                      returnData=FALSE, savePredictions=TRUE, 
                      verboseIter=TRUE, allowParallel=TRUE,
                      index=createMultiFolds(Y[train], k=folds, times=repeats))
PP <- c('center', 'scale')
model1 <- train(X[train,], Y[train], method='gbm', trControl=myControl,
            tuneGrid=expand.grid(.n.trees=500, .interaction.depth=15, .shrinkage = 0.01))
model2 <- train(X[train,], Y[train], method='blackboost', trControl=myControl)
model3 <- train(X[train,], Y[train], method='parRF', trControl=myControl)
model4 <- train(X[train,], Y[train], method='mlpWeightDecay', trControl=myControl, trace=FALSE, preProcess=PP)
model5 <- train(X[train,], Y[train], method='ppr', trControl=myControl, preProcess=PP)
model6 <- train(X[train,], Y[train], method='earth', trControl=myControl, preProcess=PP)
model7 <- train(X[train,], Y[train], method='glm', trControl=myControl, preProcess=PP)
model8 <- train(X[train,], Y[train], method='svmRadial', trControl=myControl, preProcess=PP)
model9 <- train(X[train,], Y[train], method='gam', trControl=myControl, preProcess=PP)
model10 <- train(X[train,], Y[train], method='glmnet', trControl=myControl, preProcess=PP)
all.models <- list(model1, model2, model3, model4, model5, model6, model7, model8, model9, model10)
names(all.models) <- sapply(all.models, function(x) x$method)
sort(sapply(all.models, function(x) min(x$results$RMSE)))
greedy <- caretEnsemble(all.models, iter=1000L)
Error: is(list_of_models, "caretList") is not TRUE

立ち往生するインスタンスがいくつかあります: model1 のセットアップ中に、次のエラー メッセージが表示されます。

The tuning parameter grid should have columns n.trees, interaction.depth, shrinkage, n.minobsinnode

また、貪欲なアンサンブルと線形アンサンブルをセットアップしているときに、モデルを結合するときにリスト エラーが発生します。助けを求めてください。

PS: これらが別の質問である必要がある場合は、お詫び申し上げます。

4

3 に答える 3

2

以下のビネットの例に示すように、caretlist()に渡すことができるキャレット モデル リストを作成するには、関数を使用する必要があります。caretEnsemble

model_list <- caretList(
  Class~., data=training,
  trControl=my_control,
  methodList=c("glm", "rpart")
  )

2 番目の質問に答えると、次の行は何をすると思いますか?

expand.grid(.n.trees=500, .interaction.depth=15, .shrinkage = 0.01)

3 つの値の単一の組み合わせであることをテストできます。チューニングするパラメーター値の組み合わせを複数生成するには、いずれかの列に少なくとも 2 つの値が必要です。また、名前に「.」が追加されているのはなぜですか。(ドット) 最初に?

于 2016-03-17T08:05:15.397 に答える
1

2番目の部分に答える:

method="gbm" の更新バージョンでは、tuneGrid に n.trees、interaction.depth、shrinkage、n.minobsinnode が存在する必要があります。

tuneGrid=expand.grid(.n.trees=500, .interaction.depth=6, .shrinkage = 0.01,.n.minobsinnode = c(10))

上記の場合は問題なく動作します。

于 2016-04-18T04:19:32.377 に答える