xrobin / pROC

Display and analyze ROC curves in R and S+
https://cran.r-project.org/web/packages/pROC/
GNU General Public License v3.0
121 stars 31 forks source link

Examples mentioned in https://www.rdocumentation.org/packages/pROC/versions/1.15.3/topics/multiclass.roc does not RUN #69

Closed Chandrak1907 closed 4 years ago

Chandrak1907 commented 4 years ago

Describe the bug Examples mentioned in "https://www.rdocumentation.org/packages/pROC/versions/1.15.3/topics/multiclass.roc" does not RUN. Specifically..

data(iris) iris.sample <- sample(1:150) iris.train <- iris[iris.sample[1:75],] iris.test <- iris[iris.sample[76:150],] mn.net <- nnet::multinom(Species ~ ., iris.train)

Use predict with type="prob" to get class probabilities iris.predictions <- predict(mn.net, newdata=iris.test, type="prob") head(iris.predictions)

This can be used directly in multiclass.roc: pROC::multiclass.roc(iris.test$Species, iris.predictions)

n <- c(100, 80, 150) responses <- factor(c(rep("X1", n[1]), rep("X2", n[2]), rep("X3", n[3]))) construct prediction matrix: one column per class responses preds <- lapply(n, function(x) runif(x, 0.4, 0.6)) predictor <- as.matrix(data.frame( "X1" = c(preds[[1]], runif(n[2] + n[3], 0, 0.7)), "X2" = c(runif(n[1], 0.1, 0.4), preds[[2]], runif(n[3], 0.2, 0.8)), "X3" = c(runif(n[1] + n[2], 0.3, 0.7), preds[[3]]) )) predictor pROC::multiclass.roc(responses, as.numeric(predictor))

To Reproduce Steps to reproduce the behavior:

  1. What packages were loaded? Run sessionInfo() and report the output. attached base packages: [1] tools grid splines stats graphics grDevices utils datasets [9] methods base

other attached packages: [1] e1071_1.6-7 caret_6.0-73 lattice_0.20-34 rattle_4.1.0
[5] cobalt_1.3.0 tableone_0.7.3 mlr_2.9 stringi_1.1.3
[9] ParamHelpers_1.9 BBmisc_1.10 ggplot2_1.0.0 stringr_0.6.2
[13] pROC_1.8 rpart.plot_2.1.0 ROSE_0.0-3 ROCR_1.0-7
[17] gplots_3.0.1 rpart_4.1-9 xgboost_0.4-4 digest_0.6.10
[21] rstudioapi_0.6 aetnar_0.2.2 h2osteam_1.4.8 h2o_3.24.0.5
[25] randomForest_4.6-12 geepack_1.2-1 mclust_5.2 mixtools_1.0.4
[29] devtools_1.12.0 ordinal_2015.6-28 tidyr_0.6.0 purrr_0.2.2
[33] optmatch_0.9-6 survival_2.37-7 dplyr_0.5.0 MatchIt_2.4-21
[37] MASS_7.3-39

  1. What command did you run?
  2. What data did you use? Use save(myData, file="data.RData") or save.image("data.RData")
  3. What error or output did you get?

Expected behavior A clear and concise description of what you expected to happen.

Additional context Add any other context about the problem here.

xrobin commented 4 years ago

Thanks for the report.

You aren't actually running the code of the examples in the documentation. You have:

pROC::multiclass.roc(responses, as.numeric(predictor))

but the example reads:

 pROC::multiclass.roc(responses, predictor)

which is working as expected.