crossval: Cross-validate a fitted textmodel

View source: R/crossval.R

crossvalR Documentation

Cross-validate a fitted textmodel

Description

Cross-validate a fitted textmodel using k-fold cross-validation.

Usage

crossval(x, k = 5, by_class = FALSE, verbose = FALSE)

Arguments

x

a fitted textmodel

k

number of folds

by_class

logical; if TRUE, estimate performance score separately for each class, otherwise average across classes

verbose

logical; if TRUE, output results to the console

Examples

library("quanteda")
library("quanteda.textmodels")
dfmat <- tokens(data_corpus_moviereviews) |>
  dfm()
tmod <- textmodel_nb(dfmat, y = data_corpus_moviereviews$sentiment)
crossval(tmod, k = 5, by_class = TRUE)
crossval(tmod, k = 5, by_class = FALSE)
crossval(tmod, k = 5, by_class = FALSE, verbose = TRUE)

quanteda/quanteda.classifiers documentation built on Oct. 20, 2023, 6:53 a.m.