randomForest패키지를 사용할 때 클래스 확률 은 어떻게 추정 predict(model, data, type = "prob")됩니까?
나는 확률을 예측하기 ranger위해 probability = T인수를 사용하여 임의의 숲을 훈련 하는 데 사용했습니다 . ranger설명서에서 다음과 같이 말합니다.
Malley et al. (2012).
일부 데이터를 시뮬레이트하고 패키지를 모두 시도하고 매우 다른 결과를 얻었습니다 (아래 코드 참조)
따라서 확률을 추정하기 위해 다른 기술 (그 다음 레인저)을 사용한다는 것을 알고 있습니다. 그러나 어느 것?
simulate_data <- function(n){
X <- data.frame(matrix(runif(n*10), ncol = 10))
Y <- data.frame(Y = rbinom(n, size = 1, prob = apply(X, 1, sum) %>%
pnorm(mean = 5)
) %>%
as.factor()
)
dplyr::bind_cols(X, Y)
}
treino <- simulate_data(10000)
teste <- simulate_data(10000)
library(ranger)
modelo_ranger <- ranger(Y ~., data = treino,
num.trees = 100,
mtry = floor(sqrt(10)),
write.forest = T,
min.node.size = 100,
probability = T
)
modelo_randomForest <- randomForest(Y ~., data = treino,
ntree = 100,
mtry = floor(sqrt(10)),
nodesize = 100
)
pred_ranger <- predict(modelo_ranger, teste)$predictions[,1]
pred_randomForest <- predict(modelo_randomForest, teste, type = "prob")[,2]
prob_real <- apply(teste[,1:10], 1, sum) %>% pnorm(mean = 5)
data.frame(prob_real, pred_ranger, pred_randomForest) %>%
tidyr::gather(pacote, prob, -prob_real) %>%
ggplot(aes(x = prob, y = prob_real)) + geom_point(size = 0.1) + facet_wrap(~pacote)

prob_real될까요?