Learning Discrete Bayesian Network Classifiers from Data

State-of-the art algorithms for learning discrete Bayesian network classifiers from data, including a number of those described in Bielza & Larranaga (2014) , with functions for prediction, model evaluation and inspection.


Travis-CI Build Status codecov.io CRAN_Status_Badge

Implements algorithms for learning discrete Bayesian network classifiers from data, as well as functions for using these classifiers for prediction, assessing their predictive performance, and inspecting and analyzing their properties.

Example

Load a data set and learn a one-dependence estimator by maximizing Akaike's information criterion (AIC) score.

library(bnclassify)
data(car)
tn <- tan_cl('class', car, score = 'aic')
tn
#>   Bayesian network classifier (only structure, no parameters)
#> 
#>   class variable:        class 
#>   num. features:   6 
#>   num. arcs:   9 
#>   learning algorithm:    tan_cl
plot(tn)

After learning the network's parameters, you can use it to classify data.

tn <- lp(tn, car, smooth = 0.01)
p <- predict(tn, car, prob = TRUE)
head(p)
#>      unacc          acc         good        vgood
#> [1,]     1 3.963694e-09 5.682130e-09 4.269700e-09
#> [2,]     1 1.752769e-09 3.310473e-12 3.236335e-09
#> [3,]     1 3.730170e-09 1.090296e-08 1.800719e-12
#> [4,]     1 3.963694e-09 5.682130e-09 4.269700e-09
#> [5,]     1 4.562294e-09 6.965323e-09 4.536532e-09
#> [6,]     1 4.281155e-09 5.366306e-09 5.168828e-09
p <- predict(tn, car, prob = FALSE)
head(p)
#> [1] unacc unacc unacc unacc unacc unacc
#> Levels: unacc acc good vgood

Estimate predictive accuracy with cross validation.

cv(tn, car, k = 10)
#> [1] 0.9403711

Or compute the log-likelihood

logLik(tn, car)
#> 'log Lik.' -13280.39 (df=131)

Install

Make sure you have at least version 3.2.0 of R. You will need to install packages from Bioconductor.

source("http://bioconductor.org/biocLite.R")
biocLite(c("graph", "RBGL", "Rgraphviz"))

You can install bnclassify from CRAN:

install.packages('bnclassify')

Or get the current development version from Github:

# install.packages('devtools')
devtools::install_github('bmihaljevic/bnclassify')
# devtools::install_github('bmihaljevic/bnclassify', build_vignettes = TRUE)

Ideally, you would use the build_vignettes = TRUE version, and thus get the vignettes, but it requires programs such as texi2dvi to be installed on your side.

Overview

See the list of implemented functionalities.

?bnclassify

Use the introduction vignette to get started.

vignette('introduction', package = 'bnclassify')

Then have a look at the remaining vignettes.

browseVignettes("bnclassify")

News

0.3.4

  • Added WANBIA discriminative parameter learning for naive Bayes
  • Remove 'runtimes' vignette and microbenchmark dependency

0.3.3

  • Fixed warnings for resubmission to CRAN

0.3.2

  • Improved function documentation
  • Updated and re-organized tutorial vignette
  • Added 'techical information' and 'runtimes' vignettes
  • Added logLik, AIC, and BIC
  • Memoized cpt extraction during greedy search
  • Deprecated lpawnb() (use lp() instead)
  • Fixed a number of bugs, including an error in AWNB cross-validation

0.3.1

  • Minor improvements in vignette
  • More detailed documentation for lp()
  • Fixing a test error due to a change in gRain

0.3.0

  • First released version of the package.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("bnclassify")

0.4.0 by Mihaljevic Bojan, a month ago


http://github.com/bmihaljevic/bnclassify


Report a bug at http://github.com/bmihaljevic/bnclassify/issues


Browse source code at https://github.com/cran/bnclassify


Authors: Mihaljevic Bojan [aut, cre], Bielza Concha [aut], Larranaga Pedro [aut], Wickham Hadley [ctb] (some code extracted from memoise package)


Documentation:   PDF Manual  


GPL (>= 2) license


Imports assertthat, entropy, matrixStats, rpart, Rcpp

Suggests graph, gRain, gRbase, mlr, testthat, knitr, ParamHelpers, Rgraphviz, rmarkdown, covr

Linking to Rcpp, BH

System requirements: C++11


See at CRAN