Obtaining the performance indicators of the classifier from the ROCR forecasting object
I am using ROCR to get performance measurements of various classification algorithms on my dataset. Although I can easily get the AUC figure relatively easily using the following code example:
predictions <- predict(rfmodel, test, type="prob")
pred.obj <- prediction(predictions[,2], data$response)
rfperf <- performance(pred.obj, "tpr","fpr")
print(sprintf("random forest AUC %f", as.numeric(performance(pred.obj,"auc")@y.values)))
I'm having trouble fetching other results like precision, recall, f, etc. as one value that I could include in the table in my article. I've tried the following:
> p <- performance(pred.obj,"prec", "rec")
> as.numeric(p@x.values)
Error: (list) object cannot be coerced to type 'double'
I can display the values, but that's not what I would like. Any ideas?
+3
Georgios Gousios
source
to share
2 answers
The problem is that the output is a list. Try as.numeric (unlist ( p@x.values ))
+2
Jesus herranz valera
source
to share
It has to do with the structure of the perf function's return object. Using str on it will help.
p@x.values is a single element list that is a vector of numeric values. Just use
p@x.values[[1]]
to extract the vector.
+1
Erik
source
to share