2

I use ROCR package in R. But I got the error "prediction(predictions, label) : Format of predictions is invalid."

Please tell me the solution.

here is code:

install.packages("ROCR", dependencies=TRUE)
install.packages("vcd",  dependencies=TRUE)
library(ROCR)
library(vcd)
library(boot)

setwd("/Users/Documents/R")

presence <- read.csv("sampleAverages.csv")
background <- read.csv("amplePredictions.csv")
pp <- presence$Logistic.prediction                # get the column of predictions
testpp <- pp[presence$Test.or.train=="test"]       # select only test points
trainpp <- pp[presence$Test.or.train=="train"]   # select only train points
bb <- background$logistic

combined <- c(testpp, bb)                                    # combine into a single     vector
label <- c(rep(1,length(testpp)),rep(0,length(bb)))  # labels: 1=present, 0=random
pred <- prediction(combined, label)                    # labeled predictions
perf <- performance(pred, "tpr", "fpr")               # True / false positives, for ROC curve
plot(perf, colorize=TRUE)                                  # Show the ROC curve
performance(pred, "auc")@y.values[[1]]            # Calculate the AUC
user2193548
  • 31
  • 1
  • 4

2 Answers2

0

That may be because you have wrong class of data. Try modifying the predicted data to just one column like this combined[,2] or label[,2]

user3670684
  • 1,135
  • 9
  • 8
0

check the class of the two objects (label and combined) you notice they are not the same. you can then subset the one with a different dimension with dimRid <- combined[,1]