plot error for aucpr with ROCR package
middeleast20 opened this issue · comments
Dear all,
could anyone help to find the solution for this error, and does AUC should equal the misclassification error or no?
rm(list = objects())
iris$Species <- factor(iris$Species,
-
levels = c("setosa", "versicolor", "virginica"),
-
labels = c(0, 1, 1))
ix = sample(nrow(iris), nrow(iris)/3) learn= iris[-ix,] test = iris[ix,] mod = glm(Species~., data=learn, family = "binomial")
Warning messages:
1: glm.fit: algorithm did not converge
2: glm.fit: fitted probabilities numerically 0 or 1 occurred
pred_ls = predict(mod, newdata = learn, type = "response") pred_ts = predict(mod, newdata = test, type = "response") perf_ts = ROCR::prediction(pred_ts, test$Species) auc_ts = ROCR::performance(perf_ts, "aucpr") plot(auc_ts)
Error: Performance object cannot be plotted. Length of x and y values does not match.
unlist(auc_ts@y.values[[1]])
[1] 1
perf_ls = ROCR::prediction(pred_ls, learn$Species) auc_ls = ROCR::performance(perf_ls, "aucpr") plot(auc_ls)
Error: Performance object cannot be plotted. Length of x and y values does not match.
unlist(auc_ls@y.values)
[1] 1
I am not sure, that I understand your question.
You can only plot objects, which have a measure
and a x.measure
, so this works:
auc_ts = ROCR::performance(perf_ts, "tpr", "fpr")
plot(auc_ts)
The result of your example auc_ts@y.values
also reports the correct values, since the prediction is perfect.
I suggest you read the manual ?performance
in more detail. It clearly states:
aucpr:
Area under the Precision/Recall curve. Since the output of aucpr is cutoff-independent, this measure cannot be combined with other measures into a parametric curve.
So this is behavior is expected.