2016-11-25 67 views
0

我已經繪製ROC曲線,使用ROCR包,對於一個2級難題。根據我的理解,這些曲線應該看起來像改變圖的步驟,至少對於較小的數據集。我的輸入實際上很小,但我得到的曲線基本上是直線。是否因爲PROC符合曲線或者是我缺少的其他東西?ROC曲線不是在尋找合適的

輸入是這裏click me和代碼是在末端的ROC部分如下。感謝你的幫助!

library("caret") 
library("ROCR") 
sensor6data_s10_2class <- read.csv("/home/sensei/clustering/sensor6data_f21_s10_with2Labels.csv") 
sensor6data_s10_2class <- within(sensor6data_s10_2class, Class <- as.factor(Class)) 
sensor6data_s10_2class$Class2 <- relevel(sensor6data_s10_2class$Class,ref="1") 

set.seed("4321") 
inTrain_s10_2class <- createDataPartition(y = sensor6data_s10_2class$Class, p = .75, list = FALSE) 
training_s10_2class <- sensor6data_s10_2class[inTrain_s10_2class,] 
testing_s10_2class <- sensor6data_s10_2class[-inTrain_s10_2class,] 
y_s10 <- testing_s10_2class[,22] 

ctrl_s10_2class <- trainControl(method = "repeatedcv", number = 10, repeats = 10 , savePredictions = TRUE) 
model_train_multinom_s10_2class <- train(Class2 ~ ZCR + Energy + SpectralC + SpectralS + SpectralE + SpectralF + SpectralR + MFCC1 + MFCC2 + MFCC3 + MFCC4 + MFCC5 + MFCC6 + MFCC7 + MFCC8 + MFCC9 + MFCC10 + MFCC11 + MFCC12 + MFCC13, data = training_s10_2class, method="multinom", trControl = ctrl_s10_2class) 
pred_multinom_s10_2class = predict(model_train_multinom_s10_2class, newdata=testing_s10_2class) 

pred2_s10 <- prediction(as.numeric(as.character(pred_multinom_s10_2class)), as.numeric(as.character(y_s10))) 
perf2_s10 <- performance(pred2_s10, "tpr", "fpr") 
plot(perf2_s10,col='magenta',lwd=3) 

回答

2

您應該預測類別概率而不是類別標籤。試試這個:

pred_multinom_s10_2class = predict(model_train_multinom_s10_2class, newdata=testing_s10_2class, type='prob') 

pred2_s10 <- prediction(pred_multinom_s10_2class[,1], as.numeric(as.character(y_s10))) 
perf2_s10 <- performance(pred2_s10, "tpr", "fpr") 
plot(perf2_s10,col='magenta',lwd=3) 

enter image description here

+0

這是真的,我完全忘了。謝謝你的幫助。 – tacqy2