를 사용하여 분위수 회귀 포리스트 모델을 실행 caret::train
하면 다음 오류가 발생 Error in { : task 1 failed - "non-numeric argument to binary operator"
합니다..
ntree
더 높은 숫자로 설정하면 (재현 가능한 예에서는 ntree = 150
) 코드가 오류없이 실행됩니다.
이 코드
library(caret)
library(quantregForest)
data(segmentationData)
dat <- segmentationData[segmentationData$Case == "Train",]
dat <- dat[1:50,]
# predictors
preds <- dat[,c(5:ncol(dat))]
# convert all to numeric
preds <- data.frame(sapply(preds, function(x) as.numeric(as.character(x))))
# response variable
response <- dat[,4]
# set up error measures
sumfct <- function(data, lev = NULL, model = NULL){
RMSE <- sqrt(mean((data$pred - data$obs)^2, na.omit = TRUE))
c(RMSE = RMSE)
}
# specify folds
set.seed(42, kind = "Mersenne-Twister", normal.kind = "Inversion")
folds_train <- caret::createMultiFolds(y = dat$Cell,
k = 10,
times = 5)
# specify trainControl for tuning mtry with the created multifolds
finalcontrol <- caret::trainControl(search = "grid", method = "repeatedcv", number = 10, repeats = 5,
index = folds_train, savePredictions = TRUE, summaryFunction = sumfct)
# build grid for tuning mtry
tunegrid <- expand.grid(mtry = c(2, 10, sqrt(ncol(preds)), ncol(preds)/3))
# train model
set.seed(42, kind = "Mersenne-Twister", normal.kind = "Inversion")
model <- caret::train(x = preds,
y = response,
method ="qrf",
ntree = 30, # with ntree = 150 it works
metric = "RMSE",
tuneGrid = tunegrid,
trControl = finalcontrol,
importance = TRUE,
keep.inbag = TRUE
)
오류가 발생합니다. 내 실제 데이터가있는 모델에는 ntree = 10000
여전히 작업이 실패하고 있습니다. 이 문제를 어떻게 해결할 수 있습니까?
캐럿의 소스 코드에서 오류 메시지의 조건을 찾을 수 Error in { : task 1 failed - "non-numeric argument to binary operator"
있습니까? 소스 코드의 어느 부분에서 오류 메시지가 표시됩니까?
keep.inbag = TRUE
quantregforest 코드 95 행 에서 옵션을 사용했기 때문에 오류가 발생합니다 .
minoob <- min( apply(!is.na(valuesPredict),1,sum))
if(minoob<10) stop("need to increase number of trees for sufficiently many out-of-bag observations")
따라서 모든 관측치에는 OOB (Out of Bag) 인스턴스가 10 개 이상 있어야합니다. 따라서 실제 데이터가 방대 ntrees
하다면 가방에서 꺼내는 데 필요한 것은 엄청날 것입니다.
데이터 훈련에 캐럿을 사용하는 경우 OOB를 유지하고 savePredictions = TRUE
중복되는 것처럼 보입니다. 어쨌든 테스트 접기를 사용하여 예측할 것이기 때문에 전체적으로 OOB 예측은 그다지 유용하지 않을 수 있습니다.
데이터 크기를 고려할 때 또 다른 옵션은 sampsize
. randomForest에서는 나무에 맞추기 위해 여러 sampsize
관측치 만 대체 하위 집합으로 샘플링됩니다. 이를 위해 더 낮은 크기를 설정하면 OOB가 충분한 지 확인합니다. 예를 들어 주어진 예에서 다음을 볼 수 있습니다.
model <- caret::train(x = preds,
y = response,
method ="qrf",
ntree = 30, sampsize=17,
metric = "RMSE",
tuneGrid = tunegrid,
trControl = finalcontrol,
importance = TRUE,
keep.inbag = TRUE)
model
Quantile Random Forest
50 samples
57 predictors
No pre-processing
Resampling: Cross-Validated (10 fold, repeated 5 times)
Summary of sample sizes: 44, 43, 44, 46, 45, 46, ...
Resampling results across tuning parameters:
mtry RMSE
2.000000 42.53061
7.549834 42.72116
10.000000 43.11533
19.000000 42.80340
RMSE was used to select the optimal model using the smallest value.
The final value used for the model was mtry = 2.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다