Confusion matrix

confusion(
  dataset,
  pred,
  rvar,
  lev = "",
  cost = 1,
  margin = 2,
  train = "All",
  data_filter = "",
  envir = parent.frame(),
  ...
)

Arguments

dataset

Dataset

pred

Predictions or predictors

rvar

Response variable

lev

The level in the response variable defined as success

cost

Cost for each connection (e.g., email or mailing)

margin

Margin on each customer purchase

train

Use data from training ("Training"), test ("Test"), both ("Both"), or all data ("All") to evaluate model evalbin

data_filter

Expression entered in, e.g., Data > View to filter the dataset in Radiant. The expression should be a string (e.g., "price > 10000")

envir

Environment to extract data from

...

further arguments passed to or from other methods

Value

A list of results

Details

Confusion matrix and additional metrics to evaluate binary classification models. See https://radiant-rstats.github.io/docs/model/evalbin.html for an example in Radiant

See also

summary.confusion to summarize results

plot.confusion to plot results

Examples

data.frame(buy = dvd$buy, pred1 = runif(20000), pred2 = ifelse(dvd$buy == "yes", 1, 0)) %>% confusion(c("pred1", "pred2"), "buy") %>% str()
#> List of 9 #> $ dataset : tibble [2 × 19] (S3: tbl_df/tbl/data.frame) #> ..$ Type : chr [1:2] "All" "All" #> ..$ Predictor: chr [1:2] "pred1" "pred2" #> ..$ TP : int [1:2] 2514 5246 #> ..$ FP : int [1:2] 7440 0 #> ..$ TN : int [1:2] 7314 14754 #> ..$ FN : int [1:2] 2732 0 #> ..$ total : int [1:2] 20000 20000 #> ..$ TPR : num [1:2] 0.479 1 #> ..$ TNR : num [1:2] 0.496 1 #> ..$ precision: num [1:2] 0.253 1 #> ..$ Fscore : num [1:2] 0.331 1 #> ..$ RIG : num [1:2] -0.757 1 #> ..$ accuracy : num [1:2] 0.491 1 #> ..$ kappa : num [1:2] -0.0194 1 #> ..$ profit : num [1:2] -4926 5246 #> ..$ index : num [1:2] -0.939 1 #> ..$ ROME : num [1:2] -0.495 1 #> ..$ contact : num [1:2] 0.498 0.262 #> ..$ AUC : num [1:2] 0.511 1 #> $ df_name : chr "." #> $ data_filter: chr "" #> $ train : chr "All" #> $ pred : chr [1:2] "pred1" "pred2" #> $ rvar : chr "buy" #> $ lev : chr "yes" #> $ cost : num 1 #> $ margin : num 2 #> - attr(*, "class")= chr [1:2] "confusion" "list"