Il problema con il vostro lines
-approach è che non c'è alcuna funzione generica S4
per un oggetto della classe performance
definita nel pacchetto ROCR
. Ma puoi usare la funzione di stampa generica come hai fatto con un argomento aggiuntivo add = TRUE
. Per esempio, questo è in parte dalla pagina esempio di ?plot.performance
:
library(ROCR)
data(ROCR.simple)
pred <- prediction(ROCR.simple$predictions, ROCR.simple$labels)
pred2 <- prediction(abs(ROCR.simple$predictions +
rnorm(length(ROCR.simple$predictions), 0, 0.1)),
ROCR.simple$labels)
perf <- performance(pred, "tpr", "fpr")
perf2 <- performance(pred2, "tpr", "fpr")
plot(perf, colorize = TRUE)
plot(perf2, add = TRUE, colorize = TRUE)
O, è possibile memorizzare tutti i tuoi pronostici in una matrice e fare tutte le fasi successive in uno:
preds <- cbind(p1 = ROCR.simple$predictions,
p2 = abs(ROCR.simple$predictions +
rnorm(length(ROCR.simple$predictions), 0, 0.1)))
pred.mat <- prediction(preds, labels = matrix(ROCR.simple$labels,
nrow = length(ROCR.simple$labels), ncol = 2))
perf.mat <- performance(pred.mat, "tpr", "fpr")
plot(perf.mat, colorize = TRUE)
Btw, se si per qualche motivo volevo davvero usare lines
per tracciare curve ROC consecutive che dovresti fare sth. in questo modo:
plot(perf)
lines([email protected][[1]], [email protected][[1]], col = 2)
Eccellente! Esattamente quello che stavo cercando! – kahlo