Data Mining Algorithms In R/Packages/RWeka/Weka interfaces

Description edit

Create an R interface to an existing Weka learner/filter, or show the available interfaces.

Usage edit

make_Weka_associator(name, class = NULL, init = NULL)

make_Weka_classifier(name, class = NULL, handlers = list(), init = NULL)

make_Weka_clusterer(name, class = NULL, init = NULL)

make_Weka_filter(name, class = NULL, init = NULL)

list_Weka_interfaces()

make_Weka_package_loader(p)

Arguments edit

name, a character string giving the fully qualified name of a Weka learner/filter class in JNI notation.

class, NULL (default), or a character vector giving the names of R classes the objects returned by the interface function should inherit from in addition to the default ones (for representing associators, classifiers, and clusterers).

handlers, a named list of special handler functions, see Details.

init, NULL, or a function with no arguments to be called when the interface is used for building the learner/filter, or queried for available options via WOW. Typically, this is used for loading Weka packages when interfacing functionality in these.

p, a character string naming a Weka package to be loaded via WPM.

Details edit

make_Weka_associator and make_Weka_clusterer create an R function providing an interface to a Weka association learner or a Weka clusterer, respectively. This interface function has formals x and control = NULL, representing the training instances and control options to be employed. Objects created by these interface functions always inherit from classes Weka_associator and Weka_clusterer, respectively, and have at least suitable print methods. Fitted clusterers also have a predict method.

make_Weka_classifier creates an interface function for aWeka classifier, with formals formula, data, subset, na.action, and control (default: none), where the first four have the “usual” meanings for statistical modeling functions in R, and the last again specifies the control options to be employed by the Weka learner. Objects created by these interfaces always inherit from class Weka_classifier, and have at least suitable print and predict methods.

make_Weka_filter creates an interface function for a Weka filter, with formals formula, data, subset, na.action, and control = NULL, where the first four have the “usual” meanings for statistical modeling functions in R, and the last again specifies the control options to be employed by the Weka filter. Note that the response variable can be omitted from formula if the filter is “unsupervised”. Objects created by these interface functions are (currently) always of class data.frame.

Certain aspects of the interface function can be customized by providing handlers. Currently, only control handlers (functions given as the control component of the list of handlers) are used for processing the given control arguments before passing them to theWeka classifier. This is used, e.g., by the meta learners to allow the specification of registered base learners by their “base names” (rather their full Weka/Java class names). In addition to creating interface functions, the interfaces are registered (under the name of theWeka class interfaced), which in particular allows the Weka Option Wizard (WOW) to conveniently give on-line information about available control options for the interfaces.

list_Weka_interfaces lists the available interfaces. Finally, make_Weka_package_loader generates init hooks for loading required and already installed Weka packages. It is straightforward to register new interfaces in addition to the ones package RWeka provides by default.

Example edit

   NB <- make_Weka_classifier("weka/classifiers/bayes/NaiveBayes")
   if(require("e1071", quietly = TRUE) &&     require("mlbench", quietly = TRUE)) {
       data("HouseVotes84", package = "mlbench")
       model <- NB(Class ~ ., data = HouseVotes84)
       predict(model, HouseVotes84[1:10, -1])
       predict(model, HouseVotes84[1:10, -1], type = "prob")
   }