임의 포리스트 회귀 모델의 mtry 하이퍼 파라미터를 조정하는 다음 코드가 있습니다.
set.seed(42)
mtry <- 1:10
# Define train control
trControl <- trainControl(method = "cv",
number = 10,
search = "grid")
for (i in mtry) {
rf_random <- train(Price.Gas~., data=data_train,
method = "rf",
mtry = i,
metric = "RMSE",
trControl = trControl)
}
그러나 오류가 발생합니다 (실제로 mtry의 다른 값에 대해 반복됨) .
model fit failed for Fold01: mtry= 2 Error in randomForest.default(x, y, mtry = param$mtry, ...) :
formal argument "mtry" matched by multiple actual arguments
다른 mtry 값을 테스트하려면 어떻게해야합니까?
기본적으로 캐럿은 그리드를 통해 mtry를 조정합니다. 매뉴얼을 참조 하여 루프를 사용할 필요가 없지만 대신 다음에서 정의하십시오 tuneGrid=
.
library(caret)
set.seed(42)
data_train = data.frame(Price.Gas = rnorm(100),matrix(rnorm(1000),ncol=10))
trControl <- trainControl(method = "cv",number = 10)
rf_random <- train(Price.Gas~., data=data_train,
method = "rf",
tuneGrid = data.frame(mtry = 1:10),
metric = "RMSE",
trControl = trControl)
Random Forest
100 samples
10 predictor
No pre-processing
Resampling: Cross-Validated (10 fold)
Summary of sample sizes: 89, 90, 91, 89, 91, 90, ...
Resampling results across tuning parameters:
mtry RMSE Rsquared MAE
1 0.8556649 0.2122988 0.6921878
2 0.8458829 0.2102749 0.6808978
3 0.8518204 0.1975061 0.6909111
4 0.8451160 0.1918390 0.6871511
5 0.8386129 0.2037676 0.6808157
6 0.8476718 0.1949056 0.6889514
7 0.8434816 0.2082844 0.6833892
8 0.8447137 0.1979602 0.6860908
9 0.8419739 0.1960369 0.6825207
10 0.8533284 0.1876459 0.6892574
RMSE was used to select the optimal model using the smallest value.
The final value used for the model was mtry = 5.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다