weka.classifiers.scripting
Class GroovyClassifier

java.lang.Object
  extended by weka.classifiers.AbstractClassifier
      extended by weka.classifiers.scripting.GroovyClassifier
All Implemented Interfaces:
Serializable, Cloneable, weka.classifiers.Classifier, weka.core.CapabilitiesHandler, weka.core.OptionHandler, weka.core.RevisionHandler

public class GroovyClassifier
extends weka.classifiers.AbstractClassifier

A wrapper class for Groovy code. Even though the classifier is serializable, the trained classifier cannot be stored persistently. I.e., one cannot store a model file and re-load it at a later point in time again to make predictions.

Valid options are:

 -G <filename>
  The Groovy module to load (full path)
  Options after '--' will be passed on to the Groovy module.
 -D
  If set, classifier is run in debug mode and
  may output additional info to the console
Options after "--" will be passed on to the Groovy module.

In order to use Groovy, the jar containing all the classes must be present in the CLASSPATH. This jar is normally found in the embeddable sub-directory of the Groovy installation.

Tested with Groovy 1.5.7.

Version:
$Revision: 8109 $
Author:
FracPete (fracpete at waikato dot ac dot nz)
See Also:
Groovy, Serialized Form

Constructor Summary
GroovyClassifier()
          default constructor.
 
Method Summary
 void buildClassifier(weka.core.Instances instances)
          Generates the classifier.
 double classifyInstance(weka.core.Instance instance)
          Classifies a given instance.
 double[] distributionForInstance(weka.core.Instance instance)
          Calculates the class membership probabilities for the given test instance.
 weka.core.Capabilities getCapabilities()
          Returns default capabilities of the classifier.
 File getGroovyModule()
          Gets the Groovy module.
 String getGroovyOptions()
          Gets the Groovy module options.
 String[] getOptions()
          Gets the current settings of the Classifier.
 String getRevision()
          Returns the revision string.
 String globalInfo()
          Returns a string describing classifier.
 String GroovyModuleTipText()
          Returns the tip text for this property.
 String GroovyOptionsTipText()
          Returns the tip text for this property.
 Enumeration listOptions()
          Returns an enumeration describing the available options.
static void main(String[] args)
          Main method for testing this class.
 void setGroovyModule(File value)
          Sets the Groovy module.
 void setGroovyOptions(String value)
          Sets the Groovy module options.
 void setOptions(String[] options)
          Parses a given list of options.
 String toString()
          Returns a description of the classifier.
 
Methods inherited from class weka.classifiers.AbstractClassifier
debugTipText, forName, getDebug, makeCopies, makeCopy, runClassifier, setDebug
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GroovyClassifier

public GroovyClassifier()
default constructor.

Method Detail

globalInfo

public String globalInfo()
Returns a string describing classifier.

Returns:
a description suitable for displaying in the explorer/experimenter gui

listOptions

public Enumeration listOptions()
Returns an enumeration describing the available options.

Specified by:
listOptions in interface weka.core.OptionHandler
Overrides:
listOptions in class weka.classifiers.AbstractClassifier
Returns:
an enumeration of all the available options.

setOptions

public void setOptions(String[] options)
                throws Exception
Parses a given list of options.

Specified by:
setOptions in interface weka.core.OptionHandler
Overrides:
setOptions in class weka.classifiers.AbstractClassifier
Parameters:
options - the list of options as an array of strings
Throws:
Exception - if an option is not supported

getOptions

public String[] getOptions()
Gets the current settings of the Classifier.

Specified by:
getOptions in interface weka.core.OptionHandler
Overrides:
getOptions in class weka.classifiers.AbstractClassifier
Returns:
an array of strings suitable for passing to setOptions

GroovyModuleTipText

public String GroovyModuleTipText()
Returns the tip text for this property.

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setGroovyModule

public void setGroovyModule(File value)
Sets the Groovy module.

Parameters:
value - the Groovy module

getGroovyModule

public File getGroovyModule()
Gets the Groovy module.

Returns:
the Groovy module

GroovyOptionsTipText

public String GroovyOptionsTipText()
Returns the tip text for this property.

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setGroovyOptions

public void setGroovyOptions(String value)
Sets the Groovy module options.

Parameters:
value - the options

getGroovyOptions

public String getGroovyOptions()
Gets the Groovy module options.

Returns:
the options

getCapabilities

public weka.core.Capabilities getCapabilities()
Returns default capabilities of the classifier.

Specified by:
getCapabilities in interface weka.classifiers.Classifier
Specified by:
getCapabilities in interface weka.core.CapabilitiesHandler
Overrides:
getCapabilities in class weka.classifiers.AbstractClassifier
Returns:
the capabilities of this classifier

buildClassifier

public void buildClassifier(weka.core.Instances instances)
                     throws Exception
Generates the classifier.

Parameters:
instances - set of instances serving as training data
Throws:
Exception - if the classifier has not been generated successfully

classifyInstance

public double classifyInstance(weka.core.Instance instance)
                        throws Exception
Classifies a given instance.

Specified by:
classifyInstance in interface weka.classifiers.Classifier
Overrides:
classifyInstance in class weka.classifiers.AbstractClassifier
Parameters:
instance - the instance to be classified
Returns:
index of the predicted class
Throws:
Exception - if an error occurred during the prediction

distributionForInstance

public double[] distributionForInstance(weka.core.Instance instance)
                                 throws Exception
Calculates the class membership probabilities for the given test instance.

Specified by:
distributionForInstance in interface weka.classifiers.Classifier
Overrides:
distributionForInstance in class weka.classifiers.AbstractClassifier
Parameters:
instance - the instance to be classified
Returns:
predicted class probability distribution
Throws:
Exception - if class is numeric

toString

public String toString()
Returns a description of the classifier.

Overrides:
toString in class Object
Returns:
a description of the classifier as a string.

getRevision

public String getRevision()
Returns the revision string.

Specified by:
getRevision in interface weka.core.RevisionHandler
Overrides:
getRevision in class weka.classifiers.AbstractClassifier
Returns:
the revision

main

public static void main(String[] args)
Main method for testing this class.

Parameters:
args - the options


Copyright © 2012 University of Waikato, Hamilton, NZ. All Rights Reserved.