All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home

Class weka.classifiers.IBk

java.lang.Object
    |
    +----weka.classifiers.Classifier
            |
            +----weka.classifiers.DistributionClassifier
                    |
                    +----weka.classifiers.IBk

public class IBk
extends DistributionClassifier
implements OptionHandler, UpdateableClassifier, WeightedInstancesHandler
K-nearest neighbour classifier. For more information, see

Aha, D., and D. Kibler (1991) "Instance-based learning algorithms", Machine Learning, vol.6, pp. 37-66.

Valid options are:

-K num
Set the number of nearest neighbors to use in prediction (default 1)

-W num
Set a fixed window size for incremental train/testing. As new training instances are added, oldest instances are removed to maintain the number of training instances at this size. (default no window)

-D
Neighbors will be weighted by the inverse of their distance when voting. (default equal weighting)

-F
Neighbors will be weighted by their similarity when voting. (default equal weighting)

-X
Selects the number of neighbors to use by hold-one-out cross validation, with an upper limit given by the -K option.

-S
When k is selected by cross-validation for numeric class attributes, minimize mean-squared error. (default mean absolute error)

-N
Turns off normalization.

Version:
$Revision: 1.17 $
Author:
Stuart Inglis (singlis@cs.waikato.ac.nz)
Author:
Len Trigg (trigg@cs.waikato.ac.nz)
Author:
Eibe Frank (eibe@cs.waikato.ac.nz)

Variable Index

 o TAGS_WEIGHTING
 
 o WEIGHT_INVERSE
 
 o WEIGHT_NONE
 
 o WEIGHT_SIMILARITY
 

Constructor Index

 o IBk()
IB1 classifer.
 o IBk(int)
IBk classifier.

Method Index

 o buildClassifier(Instances)
Generates the classifier.
 o distributionForInstance(Instance)
Calculates the class membership probabilities for the given test instance.
 o getAttributeMax(int)
Get an attributes maximum observed value
 o getAttributeMin(int)
Get an attributes minimum observed value
 o getCrossValidate()
Gets whether hold-one-out cross-validation will be used to select the best k value
 o getDebug()
Get the value of Debug.
 o getDistanceWeighting()
Gets the distance weighting method used.
 o getKNN()
Gets the number of neighbours the learner will use.
 o getMeanSquared()
Gets whether the mean squared error is used rather than mean absolute error when doing cross-validation.
 o getNoNormalization()
Gets whether normalization is turned off.
 o getNumTraining()
Get the number of training instances the classifier is currently using
 o getOptions()
Gets the current settings of IBk.
 o getWindowSize()
Gets the maximum number of instances allowed in the training pool.
 o listOptions()
Returns an enumeration describing the available options
 o main(String[])
Main method for testing this class.
 o setCrossValidate(boolean)
Sets whether hold-one-out cross-validation will be used to select the best k value
 o setDebug(boolean)
Set the value of Debug.
 o setDistanceWeighting(SelectedTag)
Sets the distance weighting method used.
 o setKNN(int)
Set the number of neighbours the learner is to use.
 o setMeanSquared(boolean)
Sets whether the mean squared error is used rather than mean absolute error when doing cross-validation.
 o setNoNormalization(boolean)
Set whether normalization is turned off.
 o setOptions(String[])
Parses a given list of options.
 o setWindowSize(int)
Sets the maximum number of instances allowed in the training pool.
 o toString()
Returns a description of this classifier.
 o updateClassifier(Instance)
Adds the supplied instance to the training set

Field Detail

 o WEIGHT_NONE
public static final int WEIGHT_NONE
 o WEIGHT_INVERSE
public static final int WEIGHT_INVERSE
 o WEIGHT_SIMILARITY
public static final int WEIGHT_SIMILARITY
 o TAGS_WEIGHTING
public static final Tag[] TAGS_WEIGHTING

Constructor Detail

 o IBk
public IBk(int k)
          IBk classifier. Simple instance-based learner that uses the class of the nearest k training instances for the class of the test instances.
Parameters:
k - the number of nearest neighbors to use for prediction
 o IBk
public IBk()
          IB1 classifer. Instance-based learner. Predicts the class of the single nearest training instance for each test instance.

Method Detail

 o getDebug
public boolean getDebug()
          Get the value of Debug.
Returns:
Value of Debug.
 o setDebug
public void setDebug(boolean newDebug)
          Set the value of Debug.
Parameters:
newDebug - Value to assign to Debug.
 o setKNN
public void setKNN(int k)
          Set the number of neighbours the learner is to use.
Parameters:
k - the number of neighbours.
 o getKNN
public int getKNN()
          Gets the number of neighbours the learner will use.
Returns:
the number of neighbours.
 o getWindowSize
public int getWindowSize()
          Gets the maximum number of instances allowed in the training pool. The addition of new instances above this value will result in old instances being removed. A value of 0 signifies no limit to the number of training instances.
Returns:
Value of WindowSize.
 o setWindowSize
public void setWindowSize(int newWindowSize)
          Sets the maximum number of instances allowed in the training pool. The addition of new instances above this value will result in old instances being removed. A value of 0 signifies no limit to the number of training instances.
Parameters:
newWindowSize - Value to assign to WindowSize.
 o getDistanceWeighting
public SelectedTag getDistanceWeighting()
          Gets the distance weighting method used. Will be one of WEIGHT_NONE, WEIGHT_INVERSE, or WEIGHT_SIMILARITY
Returns:
the distance weighting method used.
 o setDistanceWeighting
public void setDistanceWeighting(SelectedTag newMethod)
          Sets the distance weighting method used. Values other than WEIGHT_NONE, WEIGHT_INVERSE, or WEIGHT_SIMILARITY will be ignored.
Parameters:
newDistanceWeighting - the distance weighting method to use
 o getMeanSquared
public boolean getMeanSquared()
          Gets whether the mean squared error is used rather than mean absolute error when doing cross-validation.
Returns:
true if so.
 o setMeanSquared
public void setMeanSquared(boolean newMeanSquared)
          Sets whether the mean squared error is used rather than mean absolute error when doing cross-validation.
Parameters:
newMeanSquared - true if so.
 o getCrossValidate
public boolean getCrossValidate()
          Gets whether hold-one-out cross-validation will be used to select the best k value
Returns:
true if cross-validation will be used.
 o setCrossValidate
public void setCrossValidate(boolean newCrossValidate)
          Sets whether hold-one-out cross-validation will be used to select the best k value
Parameters:
newCrossValidate - true if cross-validation should be used.
 o getNumTraining
public int getNumTraining()
          Get the number of training instances the classifier is currently using
 o getAttributeMin
public double getAttributeMin(int index) throws java.lang.Exception
          Get an attributes minimum observed value
 o getAttributeMax
public double getAttributeMax(int index) throws java.lang.Exception
          Get an attributes maximum observed value
 o getNoNormalization
public boolean getNoNormalization()
          Gets whether normalization is turned off.
Returns:
Value of DontNormalize.
 o setNoNormalization
public void setNoNormalization(boolean v)
          Set whether normalization is turned off.
Parameters:
v - Value to assign to DontNormalize.
 o buildClassifier
public void buildClassifier(Instances instances) throws java.lang.Exception
          Generates the classifier.
Parameters:
instances - set of instances serving as training data
Throws:
java.lang.Exception - if the classifier has not been generated successfully
Overrides:
buildClassifier in class Classifier
 o updateClassifier
public void updateClassifier(Instance instance) throws java.lang.Exception
          Adds the supplied instance to the training set
Parameters:
instance - the instance to add
Throws:
java.lang.Exception - if instance could not be incorporated successfully
 o distributionForInstance
public double[] distributionForInstance(Instance instance) throws java.lang.Exception
          Calculates the class membership probabilities for the given test instance.
Parameters:
instance - the instance to be classified
Returns:
predicted class probability distribution
Throws:
java.lang.Exception - if an error occurred during the prediction
Overrides:
distributionForInstance in class DistributionClassifier
 o listOptions
public java.util.Enumeration listOptions()
          Returns an enumeration describing the available options
Returns:
an enumeration of all the available options
 o setOptions
public void setOptions(java.lang.String options[]) throws java.lang.Exception
          Parses a given list of options. Valid options are:

-K num
Set the number of nearest neighbors to use in prediction (default 1)

-W num
Set a fixed window size for incremental train/testing. As new training instances are added, oldest instances are removed to maintain the number of training instances at this size. (default no window)

-D
Neighbors will be weighted by the inverse of their distance when voting. (default equal weighting)

-F
Neighbors will be weighted by their similarity when voting. (default equal weighting)

-X
Select the number of neighbors to use by hold-one-out cross validation, with an upper limit given by the -K option.

-S
When k is selected by cross-validation for numeric class attributes, minimize mean-squared error. (default mean absolute error)

Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported
 o getOptions
public java.lang.String[] getOptions()
          Gets the current settings of IBk.
Returns:
an array of strings suitable for passing to setOptions()
 o toString
public java.lang.String toString()
          Returns a description of this classifier.
Returns:
a description of this classifier as a string.
Overrides:
toString in class java.lang.Object
 o main
public static void main(java.lang.String argv[])
          Main method for testing this class.
Parameters:
argv - should contain command line options (see setOptions)

All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home