cv {bnclassify}R Documentation

Estimate predictive accuracy with stratified cross validation.

Description

Estimate predictive accuracy of a classifier with stratified cross validation. It learns the models from the training subsamples by repeating the learning procedures used to obtain x. It can keep the network structure fixed and re-learn only the parameters, or re-learn both structure and parameters.

Usage

cv(x, dataset, k, dag = TRUE, mean = TRUE)

Arguments

x

List of bnc_bn or a single bnc_bn. The classifiers to evaluate.

dataset

The data frame on which to evaluate the classifiers.

k

An integer. The number of folds.

dag

A logical. Whether to learn structure on each training subsample. Parameters are always learned.

mean

A logical. Whether to return mean accuracy for each classifier or to return a k-row matrix with accuracies per fold.

Value

A numeric vector of same length as x, giving the predictive accuracy of each classifier. If mean = FALSE then a matrix with k rows and a column per each classifier in x.

Examples

data(car)
nb <- bnc('nb', 'class', car, smooth = 1) 
# CV a single classifier
cv(nb, car, k = 10) 
nb_manb <- bnc('nb', 'class', car, smooth = 1, manb_prior = 0.5) 
cv(list(nb=nb, manb=nb_manb), car, k = 10)
# Get accuracies on each fold
cv(list(nb=nb, manb=nb_manb), car, k = 10, mean = FALSE)
ode <- bnc('tan_cl', 'class', car, smooth = 1, dag_args = list(score = 'aic')) 
# keep structure fixed accross training subsamples
cv(ode, car, k = 10, dag = FALSE)

[Package bnclassify version 0.4.8 Index]