batch_validate: Batch validate algorithms over a list of dfms

View source: R/val.R

batch_validateR Documentation

Batch validate algorithms over a list of dfms

Description

Batch validate algorithms over a list of dfms

Usage

batch_validate(
  x,
  y,
  set = docvars(x, "training"),
  alg = NULL,
  pred = predict,
  as_matrix = FALSE,
  positive = FALSE,
  write_out = TRUE
)

Arguments

x

A dfm or list of dfms to evaluate.

y

A variable in docvars of the dfms with the class (must be logical for now).

set

A variable in docvars indicating membership to training or test set.

alg

A named list of functions containing the algorithms to be evaluated (see example)

pred

A list of prediction functions (most packages use predict(), which is the default). Either length of 1 or same length as alg.

as_matrix

A list of logical values indicating if the respective alg needs the dfm converted to a matrix.

positive

value for the positive class.

write_out

Should intermediate results be written to the working directory.

Examples

## Not run: 

library(quanteda)
corp <- corpus(c(d1 = "Chinese Beijing Chinese",
                 d2 = "Chinese Chinese Shanghai",
                 d3 = "Chinese Macao",
                 d4 = "Tokyo Japan Chinese",
                 d5 = "Chinese Chinese Chinese Tokyo Japan"))

docvars(corp, "class") <- c(TRUE, TRUE, TRUE, FALSE, FALSE)
docvars(corp, "training") <- c(TRUE, TRUE, TRUE, TRUE, FALSE)

test_prep <- batch_prep(corp)

batch_validate(x = test_prep[1:3],
               y = "class",
               set = "training",
               alg = list(textmodel_nb = quanteda.textmodels::textmodel_nb,
                          textmodel_svm = quanteda.textmodels::textmodel_svm)

## End(Not run)

JBGruber/smlhelper documentation built on Oct. 7, 2022, 3:43 p.m.