lamiastella

bayesian.classifier

Jul 19th, 2015
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 2.20 KB | None | 0 0
  1. function (data, method, training, explanatory, whitelist, blacklist,
  2.     expand, debug = FALSE)
  3. {
  4.     check.logical(debug)
  5.     check.learning.algorithm(method, class = "classifier")
  6.     check.nodes(training, max.nodes = 1)
  7.     check.data(data, allowed.types = discrete.data.types)
  8.     if (missing(data)) {
  9.         check.nodes(explanatory)
  10.     }
  11.     else {
  12.         vars = names(data)
  13.         check.nodes(training, graph = vars, max.nodes = 1)
  14.         if (missing(explanatory))
  15.             explanatory = vars[vars != training]
  16.         else check.nodes(explanatory, graph = nodes)
  17.     }
  18.     if (training %in% explanatory)
  19.         stop("node ", training, " is included in the model both as a training ",
  20.             "and an explanatory variable.")
  21.     nodes = c(training, explanatory)
  22.     if (method != "naive.bayes") {
  23.         whitelist = build.whitelist(whitelist, nodes, data, criterion = "mi")
  24.         blacklist = build.blacklist(blacklist, whitelist, nodes)
  25.         if (method == "tree.bayes") {
  26.             if ((training %in% whitelist) || (training %in% blacklist))
  27.                 stop("blacklisting arcs to and from the training node is not allowed.")
  28.         }
  29.     }
  30.     extra.args = check.classifier.args(method = method, data = data,
  31.         extra.args = expand, training = training, explanatory = explanatory)
  32.     if (method == "naive.bayes") {
  33.         ntests = 0
  34.         test = "none"
  35.         res = naive.bayes.backend(data = data, training = training,
  36.             explanatory = explanatory)
  37.     }
  38.     else if (method == "tree.bayes") {
  39.         ntests = length(explanatory) * (length(explanatory) -
  40.             1)/2
  41.         test = as.character(mi.estimator.tests[extra.args$estimator])
  42.         res = tan.backend(data = data, training = training, explanatory = explanatory,
  43.             whitelist = whitelist, blacklist = blacklist, mi = extra.args$estimator,
  44.             root = extra.args$root, debug = debug)
  45.     }
  46.     res$learning$algo = method
  47.     res$learning = list(whitelist = whitelist, blacklist = blacklist,
  48.         test = test, ntests = ntests, algo = method, args = extra.args,
  49.         optimized = NULL)
  50.     res$learning$args$training = training
  51.     invisible(res)
  52. }
Advertisement
Add Comment
Please, Sign In to add comment