2015-05-21 8 views
5

मैंने 1012 गुना क्रॉस सत्यापन के साथ caret पैकेज का train फ़ंक्शन का उपयोग किया है। मैं भी वर्ग संभावनाओं की भविष्यवाणी की कक्षाओं के लिए classProbs = TRUE की स्थापना करके trControl में, इस प्रकार मिल गया है:आर में कैरेट का उपयोग करके प्रशिक्षण के बाद आरओसी के तहत आरओसी और एयूसी की गणना कैसे करें?

myTrainingControl <- trainControl(method = "cv", 
           number = 10, 
           savePredictions = TRUE, 
           classProbs = TRUE, 
           verboseIter = TRUE) 

randomForestFit = train(x = input[3:154], 
         y = as.factor(input$Target), 
         method = "rf", 
         trControl = myTrainingControl, 
         preProcess = c("center","scale"), 
         ntree = 50) 

उत्पादन भविष्यवाणियों मैं हो रही है इस प्रकार है।

pred obs 0 1 rowIndex mtry Resample 

1 0 1 0.52 0.48  28 12 Fold01 
2 0 0 0.58 0.42  43 12 Fold01 
3 0 1 0.58 0.42  51 12 Fold01 
4 0 0 0.68 0.32  55 12 Fold01 
5 0 0 0.62 0.38  59 12 Fold01 
6 0 1 0.92 0.08  71 12 Fold01 

अब मैं इस डेटा का उपयोग कर आरओसी के तहत आरओसी और एयूसी की गणना करना चाहता हूं। मैं इसे कैसे प्राप्त करूं?

+0

आप एक खोज किया है का उपयोग कर? इसके लिए एक [आसान उदाहरण] (http://www.inside-r.org/packages/cran/caret/docs/aucRoc) प्रतीत होता है। – cfh

उत्तर

17

एयूसी के लिए एक नमूना उदाहरण:

rf_output=randomForest(x=predictor_data, y=target, importance = TRUE, ntree = 10001, proximity=TRUE, sampsize=sampsizes) 

library(ROCR) 
predictions=as.vector(rf_output$votes[,2]) 
pred=prediction(predictions,target) 

perf_AUC=performance(pred,"auc") #Calculate the AUC value 
[email protected].values[[1]] 

perf_ROC=performance(pred,"tpr","fpr") #plot the actual ROC curve 
plot(perf_ROC, main="ROC plot") 
text(0.5,0.5,paste("AUC = ",format(AUC, digits=5, scientific=FALSE))) 

या pROC और caret

library(caret) 
library(pROC) 
data(iris) 


iris <- iris[iris$Species == "virginica" | iris$Species == "versicolor", ] 
iris$Species <- factor(iris$Species) # setosa should be removed from factor 



samples <- sample(NROW(iris), NROW(iris) * .5) 
data.train <- iris[samples, ] 
data.test <- iris[-samples, ] 
forest.model <- train(Species ~., data.train) 

result.predicted.prob <- predict(forest.model, data.test, type="prob") # Prediction 

result.roc <- roc(data.test$Species, result.predicted.prob$versicolor) # Draw ROC curve. 
plot(result.roc, print.thres="best", print.thres.best.method="closest.topleft") 

result.coords <- coords(result.roc, "best", best.method="closest.topleft", ret=c("threshold", "accuracy")) 
print(result.coords)#to get threshold and accuracy 
संबंधित मुद्दे