weka.classifiers.lazy
Class LWL

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

public class LWL
extends SingleClassifierEnhancer
implements UpdateableClassifier, WeightedInstancesHandler

Locally-weighted learning. Uses an instance-based algorithm to assign instance weights which are then used by a specified WeightedInstancesHandler. A good choice for classification is NaiveBayes. LinearRegression is suitable for regression problems. For more information, see

Eibe Frank, Mark Hall, and Bernhard Pfahringer (2003). Locally Weighted Naive Bayes. Working Paper 04/03, Department of Computer Science, University of Waikato. 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)

-B classname
Specify the full class name of a base classifier (which needs to be a WeightedInstancesHandler).

Version:
$Revision: 1.9 $
Author:
Len Trigg (trigg@cs.waikato.ac.nz), Eibe Frank (eibe@cs.waikato.ac.nz)
See Also:
Serialized Form

Field Summary
protected static int GAUSS
           
protected static int INVERSE
           
protected static int LINEAR
          The available kernel weighting methods
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
 
Fields inherited from class weka.classifiers.SingleClassifierEnhancer
m_Classifier
 
Fields inherited from class weka.classifiers.Classifier
m_Debug
 
Constructor Summary
LWL()
          Constructor.
 
Method Summary
 void buildClassifier(Instances instances)
          Generates the classifier.
protected  java.lang.String defaultClassifierString()
          String describing default classifier.
private  double difference(int index, double val1, double val2)
          Computes the difference between two given attribute values.
private  double distance(Instance first, Instance second)
          Calculates the distance between two instances
 double[] distributionForInstance(Instance instance)
          Calculates the class membership probabilities 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
 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.lang.String globalInfo()
          Returns a string describing classifier
 java.lang.String KNNTipText()
          Returns the tip text for this property
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
static void main(java.lang.String[] argv)
          Main method for testing this class.
private  double norm(double x, int i)
          Normalizes a given value of a numeric attribute.
 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
private  void updateMinMax(Instance instance)
          Updates the minimum and maximum values for all the attributes based on a new instance.
 java.lang.String weightingKernelTipText()
          Returns the tip text for this property
 
Methods inherited from class weka.classifiers.SingleClassifierEnhancer
classifierTipText, getClassifier, getClassifierSpec, setClassifier
 
Methods inherited from class weka.classifiers.Classifier
classifyInstance, debugTipText, forName, getDebug, makeCopies, setDebug
 
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_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
Constructor Detail

LWL

public LWL()
Constructor.

Method Detail

globalInfo

public java.lang.String globalInfo()
Returns a string describing classifier

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

defaultClassifierString

protected java.lang.String defaultClassifierString()
String describing default classifier.

Overrides:
defaultClassifierString in class SingleClassifierEnhancer

listOptions

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

Specified by:
listOptions in interface OptionHandler
Overrides:
listOptions in class SingleClassifierEnhancer
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)

-B classname
Specify the full class name of a base classifier (which needs to be a WeightedInstancesHandler).

Specified by:
setOptions in interface OptionHandler
Overrides:
setOptions in class SingleClassifierEnhancer
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
Overrides:
getOptions in class SingleClassifierEnhancer
Returns:
an array of strings suitable for passing to setOptions

KNNTipText

public java.lang.String KNNTipText()
Returns the tip text for this property

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

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

weightingKernelTipText

public java.lang.String weightingKernelTipText()
Returns the tip text for this property

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

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

distributionForInstance

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

Overrides:
distributionForInstance in class Classifier
Parameters:
instance - the instance to be classified
Returns:
preedicted class probability distribution
Throws:
java.lang.Exception - if distribution can't be computed successfully

toString

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

Returns:
a description of this classifier as a string.

distance

private double distance(Instance first,
                        Instance second)
Calculates the distance between two instances

Returns:
the distance between the two given instances, between 0 and 1

difference

private double difference(int index,
                          double val1,
                          double val2)
Computes the difference between two given attribute values.


norm

private double norm(double x,
                    int i)
Normalizes a given value of a numeric attribute.

Parameters:
x - the value to be normalized
i - the attribute's index

updateMinMax

private void updateMinMax(Instance instance)
Updates the minimum and maximum values for all the attributes based on a new instance.

Parameters:
instance - the new instance

main

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

Parameters:
argv - the options