evalclass / precrec

An R library for accurate and fast calculations of Precision-Recall and ROC curves
https://evalclass.github.io/precrec
GNU General Public License v3.0
45 stars 5 forks source link

modnames error #9

Open c1au6i0 opened 5 years ago

c1au6i0 commented 5 years ago

I am getting an error when I set the argument modnames.

Here a reproducible example:

df <- read.csv("https://24v1ba.bn.files.1drv.com/y4msuh_tu65FeAE-CEp2SCQLTjZHhKalM9kuzlq19IN4Mu7GUWa7wxwSvtghhd5o_6VAL6S_GveZeqG8CyHa-9lzrhCRkew30v61z5t9f8a2kLp1xBMXtnaKe-GV1IDwmlS-LmOg0bkqpUYdiQX_4xcgX6dJBVqPe_1llKZ2sZhcL9LGiVtsYdWEnmNu_EHKl39/df.csv?download&psid=1")

names(df)

[1] "alpha"    "lambda"   "pred"     "obs"      "Yes"      "No"       "rowIndex" "Resample" "mod"     

and both the following lines generate an error

cvdat <- mmdata(nfold_df = df, score_cols = 5, lab_col = 4, fold_col = 8, modnames = 9)
cvdat <- mmdata(nfold_df = df, score_cols = 5, lab_col = 4, fold_col = 8, modnames = c("glmnet"))
Error: Invalid modnames and/or dsids

What am I doing wrong?

Thanks

takayasaito commented 5 years ago

Sorry for my late response. I somehow overlooked your comment.

The length of modnames vector must be the same number of your validation sets. For instance, it should be modnames = rep("model_name", 10) if your data contains 10-fold cross-validation for a single model/classifier. It can be modnames = rep(c("A", "B"), each=5) for 5-fold cross-validation for two classifiers A and B.

Alternatively, you can use auto-expansion by specifying dsids and modnames at the same time. For instance, dsids = 1:5, modnames = c("A", "B") expands to dsids = c(1,2,3,4,5,1,2,3,4,5), modnames = c("A","A","A","A","A","B","B","B","B","B") inside the mmdata function.

The auto-expansion approach requires that the product of the lengths of dsids and modnames should be matched with the total number of your validation sets. For example, length(dsids) * length(modnames) = 5 * 2 = 10 indicates that it will be extended for a data set of 5-fold cross-validation with two classifiers.

c1au6i0 commented 5 years ago

Great! Got it. Thank you so much @takayasaito :)