Package weka.classifiers.lazy

# Class LWL

java.lang.Object
weka.classifiers.Classifier
weka.classifiers.SingleClassifierEnhancer
weka.classifiers.lazy.LWL

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `UpdateableClassifier`, `CapabilitiesHandler`, `OptionHandler`, `RevisionHandler`, `TechnicalInformationHandler`, `WeightedInstancesHandler`

public class LWL extends SingleClassifierEnhancer implements UpdateableClassifier, WeightedInstancesHandler, TechnicalInformationHandler
Locally weighted learning. Uses an instance-based algorithm to assign instance weights which are then used by a specified WeightedInstancesHandler.
Can do classification (e.g. using naive Bayes) or regression (e.g. using linear regression).
For more info, see
Eibe Frank, Mark Hall, Bernhard Pfahringer: Locally Weighted Naive Bayes. In: 19th Conference in Uncertainty in Artificial Intelligence, 249-256, 2003.
C. Atkeson, A. Moore, S. Schaal (1996). Locally weighted learning. AI Review..

BibTeX:

     @inproceedings{Frank2003,
        author = {Eibe Frank and Mark Hall and Bernhard Pfahringer},
        booktitle = {19th Conference in Uncertainty in Artificial Intelligence},
        pages = {249-256},
        publisher = {Morgan Kaufmann},
        title = {Locally Weighted Naive Bayes},
        year = {2003}
     }

     @article{Atkeson1996,
        author = {C. Atkeson and A. Moore and S. Schaal},
        journal = {AI Review},
        title = {Locally weighted learning},
        year = {1996}
     }

Valid options are:

     -A
      The nearest neighbour search algorithm to use (default: weka.core.neighboursearch.LinearNNSearch).

     -K <number of neighbours>
      Set the number of neighbours used to set the kernel bandwidth.
      (default all)

     -U <number of weighting method>
      Set the weighting kernel shape to use. 0=Linear, 1=Epanechnikov,
      2=Tricube, 3=Inverse, 4=Gaussian.
      (default 0 = Linear)

     -D
      If set, classifier is run in debug mode and
      may output additional info to the console

     -W
      Full name of base classifier.
      (default: weka.classifiers.trees.DecisionStump)

     Options specific to classifier weka.classifiers.trees.DecisionStump:

     -D
      If set, classifier is run in debug mode and
      may output additional info to the console

Version:
  $Revision: 5011 $
Author:
  Len Trigg (trigg@cs.waikato.ac.nz), Eibe Frank (eibe@cs.waikato.ac.nz), Ashraf M. Kibriya (amk14[at-the-rate]cs[dot]waikato[dot]ac[dot]nz)
See Also:
  - Serialized Form

## Constructor Summary

Constructors
Constructor
Description
`LWL()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`void`
`buildClassifier(Instances instances)`
Generates the classifier.
`double[]`
`distributionForInstance(Instance instance)`
Calculates the class membership probabilities for the given test instance.
`Enumeration`
`enumerateMeasures()`
Returns an enumeration of the additional measure names produced by the neighbour search algorithm.
`Capabilities`
`getCapabilities()`
Returns default capabilities of the classifier.
`int`
`getKNN()`
Gets the number of neighbours used for kernel bandwidth setting.
`double`
`getMeasure(String additionalMeasureName)`
Returns the value of the named measure from the neighbour search algorithm.
`NearestNeighbourSearch`
`getNearestNeighbourSearchAlgorithm()`
Returns the current nearestNeighbourSearch algorithm in use.
`String[]`
`getOptions()`
Gets the current settings of the classifier.
`String`
`getRevision()`
Returns the revision string.
`TechnicalInformation`
`getTechnicalInformation()`
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.
`int`
`getWeightingKernel()`
Gets the kernel weighting method to use.
`String`
`globalInfo()`
Returns a string describing classifier.
`String`
`KNNTipText()`
Returns the tip text for this property.
`Enumeration`
`listOptions()`
Returns an enumeration describing the available options.
`static void`
`main(String[] argv)`
Main method for testing this class.
`String`
`nearestNeighbourSearchAlgorithmTipText()`
Returns the tip text for this property.
`void`
`setKNN(int knn)`
Sets the number of neighbours used for kernel bandwidth setting.
`void`
`setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch nearestNeighbourSearchAlgorithm)`
Sets the nearestNeighbourSearch algorithm to be used for finding nearest neighbour(s).
`void`
`setOptions(String[] options)`
Parses a given list of options.
`void`
`setWeightingKernel(int kernel)`
Sets the kernel weighting method to use.
`String`
`toString()`
Returns a description of this classifier.
`void`
`updateClassifier(Instance instance)`
Adds the supplied instance to the training set.
`String`
`weightingKernelTipText()`
Returns the tip text for this property.

### Methods inherited from class weka.classifiers.SingleClassifierEnhancer

`classifierTipText, getClassifier, setClassifier`

### Methods inherited from class weka.classifiers.Classifier

`classifyInstance, debugTipText, forName, getDebug, makeCopies, makeCopy, setDebug`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### LWL

public LWL()
Constructor.

## Method Details

### globalInfo

public String globalInfo()
Returns a string describing classifier.

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

### getTechnicalInformation

public TechnicalInformation getTechnicalInformation()
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.

Specified by:
  `getTechnicalInformation` in interface `TechnicalInformationHandler`
Returns:
  the technical information about this class

### enumerateMeasures

public Enumeration enumerateMeasures()
Returns an enumeration of the additional measure names produced by the neighbour search algorithm.

Returns:
  an enumeration of the measure names

### getMeasure

public double getMeasure(String additionalMeasureName)
Returns the value of the named measure from the neighbour search algorithm.

Parameters:
  `additionalMeasureName` - the name of the measure to query for its value
Returns:
  the value of the named measure
Throws:
  `IllegalArgumentException` - if the named measure is not supported

### listOptions

public 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(String[] options) throws Exception
Parses a given list of options.

Valid options are:

     -A
      The nearest neighbour search algorithm to use (default: weka.core.neighboursearch.LinearNNSearch).

     -K <number of neighbours>
      Set the number of neighbours used to set the kernel bandwidth.
      (default all)

     -U <number of weighting method>
      Set the weighting kernel shape to use. 0=Linear, 1=Epanechnikov,
      2=Tricube, 3=Inverse, 4=Gaussian.
      (default 0 = Linear)

     -D
      If set, classifier is run in debug mode and
      may output additional info to the console

     -W
      Full name of base classifier.
      (default: weka.classifiers.trees.DecisionStump)

     Options specific to classifier weka.classifiers.trees.DecisionStump:

     -D
      If set, classifier is run in debug mode and
      may output additional info to the console

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

### KNNTipText

public 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 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, EPANECHNIKOV, TRICUBE, INVERSE, GAUSS or CONSTANT, other values are ignored.

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

### getWeightingKernel

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

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

### nearestNeighbourSearchAlgorithmTipText

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

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

### getNearestNeighbourSearchAlgorithm

public NearestNeighbourSearch getNearestNeighbourSearchAlgorithm()
Returns the current nearestNeighbourSearch algorithm in use.

Returns:
  the NearestNeighbourSearch algorithm currently in use.

### setNearestNeighbourSearchAlgorithm

public void setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch nearestNeighbourSearchAlgorithm)
Sets the nearestNeighbourSearch algorithm to be used for finding nearest neighbour(s).

Parameters:
  `nearestNeighbourSearchAlgorithm` - - The NearestNeighbourSearch class.

### getCapabilities

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

Specified by:
  `getCapabilities` in interface `CapabilitiesHandler`
Overrides:
  `getCapabilities` in class `SingleClassifierEnhancer`
Returns:
  the capabilities of this classifier
See Also:
  - `Capabilities`

### buildClassifier

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

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

### updateClassifier

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

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

### distributionForInstance

public double[] distributionForInstance(Instance instance) throws 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:
  `Exception` - if distribution can't be computed successfully

### toString

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

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

### getRevision

public String getRevision()
Returns the revision string.

Specified by:
  `getRevision` in interface `RevisionHandler`
Overrides:
  `getRevision` in class `Classifier`
Returns:
  the revision

### main

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

Parameters:
  `argv` - the options