Search code examples
rrweka

How to use RWeka classifiers function attribute "options"?


In RWeka classifiers, there is an attribute "options" in the classifier's function call, e.g. Bagging(formula, data, subset, na.action, control = Weka_control(), options = NULL). Could some one please give an example (a sample R code) on how to define these options?

I would be interested in passing on some options (such as the number of iterations and size of each bag) to Bagging meta learner of RWeka. Thanks in advance!


Solution

  • You can get at the features that you mentioned, but not through options.

    First, what does options do? According to the help page ?Bagging

    Argument options allows further customization. Currently, options model and instances (or partial matches for these) are used: if set to TRUE, the model frame or the corresponding Weka instances, respectively, are included in the fitted model object, possibly speeding up subsequent computations on the object. By default, neither is included.

    So options simply stores more information in the returned result. To get at the features that you want, you need to use control. You will need to construct the value for control using the function Weka_control. Without some help, it is hard to know how to use that, but luckily, help is available through WOW the Weka Option Wizard. Because there are many options, the output is long. I am going to truncate it to just the part about the features that you mentioned - the number of iterations and size of each bag. But do look at what else is available.

    WOW(Bagging)
    -P      Size of each bag, as a percentage of the training set size. (default 100)
    -I <num>
            Number of iterations.  (current value 10)
            Number of arguments: 1.
    

    Repeating: I have truncated the output to show just these two options.

    Example: Iris data

    Suppose that I wanted to use bagging with the iris data with the bag size being 90% of the data (instead of the default 100%) and with 20 iterations (instead of the default 10). First, I would build the Weka_control, then include that in my call to Bagging.

    WC = Weka_control(P=90, I=20) 
    BagOfIrises = Bagging(Species ~ ., data=iris, control=WC)
    

    I hope that this helps.