2017-01-07 1 views
1

SVM 모델을 적용하고 ROCR 패키지로 ROC 커브를 만들었습니다. 곡선 아래 면적 (AUC)은 어떻게 계산합니까?ROCR 패키지로 AUC를 계산하는 방법

tune.out=tune(svm ,Negative~.-Positive, data=trainSparse, kernel ="radial", 
       ranges=list(cost=c(0.1,1,10,100,1000),gamma=c(0.5,1,2,3,4), 
       probability = TRUE)) # train svm with probability option true 
summary(tune.out) 
best=tune.out$best.model 
yhat.opt = predict(best,testSparse,probability = TRUE) 

# Roc curve 
library(ROCR) 
# choose the probability column carefully, it may be 
# probabilities[,1] or probabilities[,2], depending on your factor levels 
pred <- prediction(attributes(yhat.opt)$probabilities[,2], testSparse$Negative) 
perf <- performance(pred,"tpr","fpr") 
plot(perf,colorize=TRUE) 

enter image description here

+0

안녕하세요, 유래에 오신 것을 환영합니다! 다음 내용을 읽으십시오. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example –

답변

1

이 시도

... 
prediction.obj <- prediction(...) 
perf <- performance(prediction.obj, measure = "auc") 
print("AUC: ", [email protected]) 

sandipan's code 다음에 추가 할 수 있습니다. 당신 혼자 음모. ftp://ftp.auckland.ac.nz/pub/software/CRAN/doc/packages/ROCR.pdf

"auc"performance을 수득 할 수있는 가능한 방법 중 하나이다 :

페이지 5 performance ROCR 대한 설명서를 참조.

+0

df 란 무엇입니까? 그 명령을 실행하면 다음과 같이 나타납니다 : df $ Negative <- as.factor (df $ Negative) df $에서 오류가 발생했습니다. Negative : 'closure'유형의 객체는 하위 집합이 아닙니다 @sandipan –

+0

df는 두 부분, 기차 및 테스트)에 대해 걱정할 필요는 없습니다. 네거티브 변수가 중요한 요소인지 확인하십시오. –

+0

나는 이것을 만들었 기 때문에 ok : tweets $ Negative = as.factor (tweets $ Sent <= - 1) 그리고 명령의 다른 부분은 잘 작동합니다. 고마워요. 내가 명성 15에 도달 할 때, 나는 당신에게 upvote !! @ 샌드 피판 –

2

귀하의 예는 완전하지 않는 것, 그래서 그것을 실행하고 적절하게 변경 할 수있을 것 수는 없지만 :

set.seed(1) 
tune.out=tune(svm ,Negative~.-Positive, data=trainSparse, kernel ="radial",ranges=list(cost=c(0.1,1,10,100,1000),gamma=c(0.5,1,2,3,4))) 
summary(tune.out) 
best=tune.out$best.model 

##prediction on the test set 
ypred = predict(best,testSparse, type = "class") 
table(testSparse$Negative,ypred) 

###Roc curve 
yhat.opt = predict(best,testSparse,decision.values = TRUE) 
fitted.opt = attributes(yhat.opt)$decision.values 
rocplot(fitted.opt,testSparse ["Negative"], main = "Test Data")## 
0

prediction 시작 방법 ROCR 패키지에서 시작하십시오. AUC 값을

roc_ROCR <- performance(pred_ROCR, measure = "tpr", x.measure = "fpr") 
plot(roc_ROCR, main = "ROC curve", colorize = T) 
abline(a = 0, b = 1) 

를 얻을 :

pred_ROCR <- prediction(df$probabilities, df$target) 

플롯의 ROC를 얻을 수

auc_ROCR <- performance(pred_ROCR, measure = "auc") 
    auc_ROCR <- [email protected][[1]] 
관련 문제