format_nfold {precrec} | R Documentation |
Create n-fold cross validation dataset from data frame
Description
The format_nfold
function takes a data frame with scores, label,
and n-fold columns and convert it to a list for evalmod
and mmdata
.
Usage
format_nfold(nfold_df, score_cols, lab_col, fold_col)
Arguments
nfold_df |
A data frame that contains at least one score column, label and fold columns. |
score_cols |
A character/numeric vector that specifies score columns
of |
lab_col |
A number/string that specifies the label column
of |
fold_col |
A number/string that specifies the fold column
of |
Value
The format_nfold
function returns a list that
contains multiple scores and labels.
See Also
evalmod
for calculation evaluation measures.
mmdata
for formatting input data.
join_scores
and join_labels
for formatting
scores and labels with multiple datasets.
Examples
##################################################
### Convert dataframe with 2 models and 5-fold datasets
###
## Load test data
data(M2N50F5)
head(M2N50F5)
## Convert with format_nfold
nfold_list1 <- format_nfold(
nfold_df = M2N50F5, score_cols = c(1, 2),
lab_col = 3, fold_col = 4
)
## Show the list structure
str(nfold_list1)
str(nfold_list1$scores)
str(nfold_list1$labels)
##################################################
### Speficy a single score column
###
## Convert with format_nfold
nfold_list2 <- format_nfold(
nfold_df = M2N50F5, score_cols = 1,
lab_col = 3, fold_col = 4
)
## Show the list structure
str(nfold_list2)
str(nfold_list2$scores)
str(nfold_list2$labels)
##################################################
### Use column names
###
## Convert with format_nfold
nfold_list3 <- format_nfold(
nfold_df = M2N50F5,
score_cols = c("score1", "score2"),
lab_col = "label", fold_col = "fold"
)
## Show the list structure
str(nfold_list3)
str(nfold_list3$scores)
str(nfold_list3$labels)
[Package precrec version 0.14.4 Index]