weka.classifiers.lazy
Class LWR

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.lazy.LWR
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable, UpdateableClassifier, WeightedInstancesHandler

public class LWR
extends Classifier
implements OptionHandler, UpdateableClassifier, WeightedInstancesHandler

Locally-weighted regression. Uses an instance-based algorithm to assign instance weights which are then used by a linear regression model. For more information, see

Atkeson, C., A. Moore, and S. Schaal (1996) Locally weighted learning download postscript.

Valid options are:

-D
Produce debugging output.

-K num
Set the number of neighbours used for setting kernel bandwidth. (default all)

-W num
Set the weighting kernel shape to use. 1 = Inverse, 2 = Gaussian. (default 0 = Linear)

-S num
Set the attriute selection method to use. 1 = None, 2 = Greedy (default 0 = M5' method)

-C
Do not try to eliminate colinear attributes

-R num
The ridge parameter (default 1.0e-8)

See Also:
Serialized Form

Field Summary
protected static int GAUSS
           
protected static int INVERSE
           
protected static int LINEAR
          The available kernel weighting methods
protected  LinearRegression lr
          The linear regression object
protected  boolean m_Debug
          True if debugging output should be printed
protected  int m_kNN
          The number of neighbours used to select the kernel bandwidth
protected  double[] m_Max
          The maximum values for numeric attributes.
protected  double[] m_Min
          The minimum values for numeric attributes.
protected  Instances m_Train
          The training instances used for classification.
protected  boolean m_UseAllK
          True if m_kNN should be set to all instances
protected  int m_WeightKernel
          The weighting kernel method currently selected
 
Constructor Summary
LWR()
           
 
Method Summary
 void buildClassifier(Instances instances)
          Generates the classifier.
 double classifyInstance(Instance instance)
          Predicts the class value for the given test instance.
protected  double getAttributeMax(int index)
          Gets an attributes maximum observed value
protected  double getAttributeMin(int index)
          Gets an attributes minimum observed value
 SelectedTag getAttributeSelectionMethod()
          Gets the method used to select attributes for use in the linear regression.
 boolean getDebug()
          SGts whether debugging output should be produced
 boolean getEliminateColinearAttributes()
          Get the value of EliminateColinearAttributes.
 int getKNN()
          Gets the number of neighbours used for kernel bandwidth setting.
 java.lang.String[] getOptions()
          Gets the current settings of the classifier.
 int getWeightingKernel()
          Gets the kernel weighting method to use.
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
static void main(java.lang.String[] argv)
          Main method for testing this class.
 void setAttributeSelectionMethod(SelectedTag method)
          Sets the method used to select attributes for use in the linear regression.
 void setDebug(boolean debug)
          Sets whether debugging output should be produced
 void setEliminateColinearAttributes(boolean newEliminateColinearAttributes)
          Set the value of EliminateColinearAttributes.
 void setKNN(int knn)
          Sets the number of neighbours used for kernel bandwidth setting.
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setWeightingKernel(int kernel)
          Sets the kernel weighting method to use.
 java.lang.String toString()
          Returns a description of this classifier.
 void updateClassifier(Instance instance)
          Adds the supplied instance to the training set
 
Methods inherited from class weka.classifiers.Classifier
forName, makeCopies
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Train

protected Instances m_Train
The training instances used for classification.


m_Min

protected double[] m_Min
The minimum values for numeric attributes.


m_Max

protected double[] m_Max
The maximum values for numeric attributes.


m_Debug

protected boolean m_Debug
True if debugging output should be printed


m_kNN

protected int m_kNN
The number of neighbours used to select the kernel bandwidth


m_WeightKernel

protected int m_WeightKernel
The weighting kernel method currently selected


m_UseAllK

protected boolean m_UseAllK
True if m_kNN should be set to all instances


LINEAR

protected static final int LINEAR
The available kernel weighting methods

See Also:
Constant Field Values

INVERSE

protected static final int INVERSE
See Also:
Constant Field Values

GAUSS

protected static final int GAUSS
See Also:
Constant Field Values

lr

protected LinearRegression lr
The linear regression object

Constructor Detail

LWR

public LWR()
Method Detail

listOptions

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

Specified by:
listOptions in interface OptionHandler
Returns:
an enumeration of all the available options.

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options. Valid options are:

-D
Produce debugging output.

-K num
Set the number of neighbours used for setting kernel bandwidth. (default all)

-W num
Set the weighting kernel shape to use. 1 = Inverse, 2 = Gaussian. (default 0 = Linear)

-S num
Set the attriute selection method to use. 1 = None, 2 = Greedy (default 0 = M5' method)

-C
Do not try to eliminate colinear attributes

-R num
The ridge parameter (default 1.0e-8)

Specified by:
setOptions in interface OptionHandler
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported

getOptions

public java.lang.String[] getOptions()
Gets the current settings of the classifier.

Specified by:
getOptions in interface OptionHandler
Returns:
an array of strings suitable for passing to setOptions

getEliminateColinearAttributes

public boolean getEliminateColinearAttributes()
Get the value of EliminateColinearAttributes.

Returns:
Value of EliminateColinearAttributes.

setEliminateColinearAttributes

public void setEliminateColinearAttributes(boolean newEliminateColinearAttributes)
Set the value of EliminateColinearAttributes.

Parameters:
newEliminateColinearAttributes - Value to assign to EliminateColinearAttributes.

setAttributeSelectionMethod

public void setAttributeSelectionMethod(SelectedTag method)
Sets the method used to select attributes for use in the linear regression.

Parameters:
method - the attribute selection method to use.

getAttributeSelectionMethod

public SelectedTag getAttributeSelectionMethod()
Gets the method used to select attributes for use in the linear regression.

Returns:
the method to use.

setDebug

public void setDebug(boolean debug)
Sets whether debugging output should be produced

Parameters:
debug - true if debugging output should be printed

getDebug

public boolean getDebug()
SGts whether debugging output should be produced

Returns:
true if debugging output should be printed

setKNN

public void setKNN(int knn)
Sets the number of neighbours used for kernel bandwidth setting. The bandwidth is taken as the distance to the kth neighbour.

Parameters:
knn - the number of neighbours included inside the kernel bandwidth, or 0 to specify using all neighbors.

getKNN

public int getKNN()
Gets the number of neighbours used for kernel bandwidth setting. The bandwidth is taken as the distance to the kth neighbour.

Returns:
the number of neighbours included inside the kernel bandwidth, or 0 for all neighbours

setWeightingKernel

public void setWeightingKernel(int kernel)
Sets the kernel weighting method to use. Must be one of LINEAR, INVERSE, or GAUSS, other values are ignored.

Parameters:
kernel - the new kernel method to use. Must be one of LINEAR, INVERSE, or GAUSS

getWeightingKernel

public int getWeightingKernel()
Gets the kernel weighting method to use.

Returns:
the new kernel method to use. Will be one of LINEAR, INVERSE, or GAUSS

getAttributeMin

protected double getAttributeMin(int index)
Gets an attributes minimum observed value

Parameters:
index - the index of the attribute
Returns:
the minimum observed value

getAttributeMax

protected double getAttributeMax(int index)
Gets an attributes maximum observed value

Parameters:
index - the index of the attribute
Returns:
the maximum observed value

buildClassifier

public void buildClassifier(Instances instances)
                     throws java.lang.Exception
Generates the classifier.

Specified by:
buildClassifier in class Classifier
Parameters:
instances - set of instances serving as training data
Throws:
java.lang.Exception - if the classifier has not been generated successfully

updateClassifier

public void updateClassifier(Instance instance)
                      throws java.lang.Exception
Adds the supplied instance to the training set

Specified by:
updateClassifier in interface UpdateableClassifier
Parameters:
instance - the instance to add
Throws:
java.lang.Exception - if instance could not be incorporated successfully

classifyInstance

public double classifyInstance(Instance instance)
                        throws java.lang.Exception
Predicts the class value for the given test instance.

Specified by:
classifyInstance in class Classifier
Parameters:
instance - the instance to be classified
Returns:
the predicted class value
Throws:
java.lang.Exception - if an error occurred during the prediction

toString

public java.lang.String toString()
Returns a description of this classifier.

Returns:
a description of this classifier as a string.

main

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

Parameters:
argv - the options