我想使用插入符号训练一些模型,然后在调整了参数后,将caretEnsemble与各个模型进行比较。我正在波士顿房屋数据集上对此进行测试。到目前为止,我的代码是:
library(caret)
library(ranger)
library(randomForest)
library(caretEnsemble)
library(xgboost)
library(mlbench)
library(e1071)
library(GAMBoost)
library(quantregForest)
library(glmnet)
#load in boston housing dataset
data(BostonHousing)
df <- data.frame(BostonHousing)
#set random seed for reproduction
set.seed(54321)
#break into train and test
indexes <- createDataPartition(df$medv, times = 1, p = 0.7, list = FALSE)
train <- df[indexes,]
test <- df[-indexes,]
#set train control
my_control <- trainControl(method = "repeatedcv",
number = 10,
repeats = 3,
savePredictions = 'final',
allowParallel = T,
index = createResample(train$medv, 25))
#create the model list, tuneLength here should get tuning paramaters
model_list <- caretList(
medv~., data=train,
trControl=my_control,
metric="RMSE",
methodList=c("glm"),
tuneList=list(
ranger=caretModelSpec(method = 'ranger', tuneLength = 2),
rf=caretModelSpec(method = 'rf', tuneLength = 2),
quantile=caretModelSpec(method = 'qrf', tuneLength = 2),
ridge=caretModelSpec(method = 'ridge', tuneLength = 2),
bam=caretModelSpec(method = 'gamboost', tuneLength = 2),
svm=caretModelSpec(method = 'svmPoly', tuneLength = 2)
)
)
这时我得到了错误:
Something is wrong; all the RMSE metric values are missing:
RMSE Rsquared MAE
Min. : NA Min. : NA Min. : NA
1st Qu.: NA 1st Qu.: NA 1st Qu.: NA
Median : NA Median : NA Median : NA
Mean :NaN Mean :NaN Mean :NaN
3rd Qu.: NA 3rd Qu.: NA 3rd Qu.: NA
Max. : NA Max. : NA Max. : NA
NA's :2 NA's :2 NA's :2
Error: Stopping
In addition: There were 50 or more warnings (use warnings() to see the first 50)
我不明白为什么。如果一切正常,我想做的其余工作如下:
#set new seed
set.seed(101)
#set new train control
trainControl = trainControl(method="repeatedcv",
number=10,
repeats=3,
savePredictions='final',
allowParallel = T,
index = createResample(train$medv, 25))
#ensemble the models
greedy_ensemble <- caretEnsemble(
model_list,
metric="RMSE",
trControl=trainControl)
summary(greedy_ensemble)
#predict on test data
stack_predicteds <- predict(greedy_ensemble, newdata=test)
head(stack_predicteds)