기반이 상호 작용의 깊이 (14)와 (20) 사이에서 변화하며, 나무의 수축 및 수가 고정되어
library(caret)
library(gbm)
attach(origData)
gbmGrid <- expand.grid(.n.trees = c(2000),
.interaction.depth = c(14:20),
.shrinkage = c(0.005))
trainedGBM <- train(y ~ ., method = "gbm", distribution = "gaussian",
data = origData, tuneGrid = gbmGrid,
trControl = trainControl(method = "repeatedcv", number = 10,
repeats = 3, verboseIter = FALSE,
returnResamp = "all"))
ntrees <- gbm.perf(trainedGBM$finalModel, method="OOB")
data.frame(y,
finalModelFit = trainedGBM$finalModel$fit,
predictDataSpec = predict(trainedGBM$finalModel, origData, type="response", n.trees=ntrees),
predictNoDataSpec = predict(trainedGBM$finalModel, type="response", n.trees=ntrees))
상기 코드는 다음의 부분적인 결과를 얻을 0.005, 2000으로 각각 나타났다. TrainedGBM
은 현재와 같은 최적의 상호 작용 수준만을 찾도록 설계되었습니다. 최적 수준의 상호 작용이 14에서 20 사이 인 경우 OOB 기준에 따라 최적의 트리 수는 얼마입니까? 이 gbm.perf
에서 계산됩니다. 예측은 모델의 트리 수에 따라 다르므로 훈련 된 GBM을 기반으로 한 예측은 ntrees = 2000
이고 예측은 gbm.perf
을 기반으로하며 해당 함수에서 추정 한 최적 수는 ntrees
입니다. 이는 trainedGBM$finalModel$fit
과 predict(trainedGBM$finalModel, type="response", n.trees=ntrees)
의 차이를 설명합니다.
홍채 데이터를 기반으로 예를 표시하려면 최적의 상호 작용을 깊이 조건으로 나무의 최적의 수를 찾기
# Resampling results across tuning parameters:
# interaction.depth Accuracy Kappa Accuracy SD Kappa SD
# 1 0.947 0.92 0.0407 0.061
# 2 0.947 0.92 0.0407 0.061
# 3 0.944 0.917 0.0432 0.0648
# 4 0.944 0.917 0.0395 0.0592
# Tuning parameter 'n.trees' was held constant at a value of 100
# Tuning parameter 'shrinkage' was held constant at a value of 0.05
# Accuracy was used to select the optimal model using the largest value.
# The final values used for the model were interaction.depth = 1, n.trees = 100
# and shrinkage = 0.05.
을주고 분류보다는 회귀 모델
library(caret)
library(gbm)
set.seed(42)
gbmGrid <- expand.grid(.n.trees = 100,
.interaction.depth = 1:4,
.shrinkage = 0.05)
trainedGBM <- train(Species ~ ., method = "gbm", distribution='multinomial',
data = iris, tuneGrid = gbmGrid,
trControl = trainControl(method = "repeatedcv", number = 10,
repeats = 3, verboseIter = FALSE,
returnResamp = "all"))
print(trainedGBM)
으로 GBM를 사용하여 설정 :
ntrees <- gbm.perf(trainedGBM$finalModel, method="OOB")
# Giving ntrees = 50
나무 수를 변경하여 모델을 훈련 시키면 및 상호 작용 깊이 : 나무의 최적의 수는 우리가 나무와 상호 작용 깊이의 번호가 모두 다를 수 있다는
gbmGrid2 <- expand.grid(.n.trees = 1:100,
.interaction.depth = 1:4,
.shrinkage = 0.05)
trainedGBM2 <- train(Species ~ ., method = "gbm",
data = iris, tuneGrid = gbmGrid2,
trControl = trainControl(method = "repeatedcv", number = 10,
repeats = 3, verboseIter = FALSE,
returnResamp = "all"))
print(trainedGBM2)
# Tuning parameter 'shrinkage' was held constant at a value of 0.05
# Accuracy was used to select the optimal model using the largest value.
# The final values used for the model were interaction.depth = 2, n.trees = 39
# and shrinkage = 0.05.
주 gbm.perf
에 대해 계산이 상당히 가깝습니다.
이것이 '캐럿 (caret)'패키지에 있다고 맞습니까? 당신이해야 할 일이'라이브러리 (_whatever_package_train_came_from)'에 넣어 졌을 때 사람들이 이런 종류의 질문을하게하는 것은 정말로 무의미하다. –
또 하나의 별개의 whinge로 :'attach '를 사용하는 것은 이해하기 힘든 공통 소스이다. 오류. 물론 "origData"에 대해 더 자세히 설명해야합니다. –
여기에 어떤 종류의 데이터 설명이 유용합니까? 필자는 약 7000 개의 레코드를 가지고 있는데, y는 26 개의 기능, 둘 다 요소 및 숫자의 함수로 적합합니다. – Nostradamus