2010-01-18 70 views
2

Q1: 我一直在嘗試獲取分類問題的AUC值,並一直試圖在R中使用e1071和ROCR包。 ROCR有一個很好的例子「ROCR.simple」,它有預測值和標籤值。如何從e1071包中運行svm得到預測列表

library(ROCR) 
data(ROCR.simple) 
pred<-prediction(ROCR.simpe$predictions, ROCR.simple$labels) 
auc<-performance(pred,"auc") 

這給出了AUC值,沒有問題。 我的問題是:如何獲得ROCR.simple$predictions在上例中給出的數據類型? 我運行我的分析就像

library(e1071) 
data(iris) 
y<-Species 
x<-iris[,1:2] 
model<-svm(x,y) 
pred<-predict(model,x) 

高興在這裏我很好。 那我該如何得到ROCR.simpe$predictions給出的那種預測呢?

Q2:

有涉及ROCR.xvals一個很好的例子。這是10個交叉驗證的問題。

他們跑得

pred<-prediction(ROCR.xval$predictions,ROCR.xval$labels) 
auc<-performance(pred,"auc") 

這給了所有10個交叉驗證結果。

我的問題是:

如何使用

model<-svm(x,y,cross=10)  # where x and y are as given in Q1 

,並得到預測和標籤的所有10個結果到一個列表中給出ROCR.xvals

回答

4

Q1。你可以使用

pred<-prediction(as.numeric(pred), as.numeric(iris$Species)) 
auc<-performance(pred,"auc") 

但是。類別數目不等於2. ROCR目前僅支持評估二進制分類任務(根據我得到的錯誤)

Q2。我不認爲第二個可以按照你想要的方式完成。我只能想到進行交叉驗證manualy即

獲得resample.indices(從包裝peperr)

cv.ind <- resample.indices(nrow(iris), sample.n = 10, method = c("cv")) 
x <- lapply(cv.ind$sample.index,function(x){iris[x,1:2]}) 
y <- lapply(cv.ind$sample.index,function(x){iris[x,5]}) 

然後生成模型和預測每個品種樣品

model1<-svm(x[[1]],y[[1]]) 
pred1<-predict(model1,x[[1]]) 

等 然後您可以手動構建一個列表,如ROCR.xval