confidenceMachine.tcm
Class TCMKNearestNeighbours

java.lang.Object
  |
  +--weka.classifiers.Classifier
        |
        +--confidenceMachine.ConfidenceClassifier
              |
              +--confidenceMachine.tcm.TCMKNearestNeighbours
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable, UpdateableClassifier

public class TCMKNearestNeighbours
extends ConfidenceClassifier
implements UpdateableClassifier, OptionHandler

The TCM K-Nearest Neighbours algorithm. With this particular implementation is embedded, meaning that the traditional K has been altered slightly to adapt a strangeness measure using a ratio of the K nearest distances to the predicted class and all other classes. For more information, see

Transductive Confidence Machines for Pattern Recognition, CRLC Technical Report CRLC-TR-01-02, June 18 2001, Kostas Proedrou, Ilia Nouretdinov, Volodya Vovk, Alex Gammerman -Q Distance Metric
This is the distance metric that we are using (default Euclidean distance)

Version:
$Revision: 1.0 $
Author:
David Lindsay (davidl@cs.rhul.ac.uk)
See Also:
Serialized Form

Constructor Summary
TCMKNearestNeighbours()
          The amazing TCM K Nearest Neighbours classifier
TCMKNearestNeighbours(int k)
          The amazing TCM K Nearest Neighbours classifier
 
Method Summary
 void buildClassifier(Instances instances)
          Generates the classifier.
 int getDebugEvery()
          Reports whether the TCM is currently in debug mode (if not -1), and specifies how frequently to output message about TCM's progress on data.
 java.lang.String getDistanceMetric()
          The gives details about the distance metric that has been chosen
 int getKNN()
          Gets the number of neighbours the learner will use.
 java.lang.String[] getOptions()
          Gets the current settings of TCM.
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options
static void main(java.lang.String[] argv)
          Main method for testing this class.
 double[] pValuesForInstance(Instance instance)
          Returns the p-values for a given test instance.
 void setDebugEvery(int debug)
          Set the TCM to debug its output, outputting progress as it goes along.
 boolean setDistanceMetric(java.lang.String distName, java.lang.String[] distOptions)
          Set the distance metric
 void setKNN(int k)
          Set the number of neighbours the learner is to use.
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 java.lang.String toString()
          Returns a description of this classifier.
 void updateClassifier(Instance instance)
          Updates the classifier.
 
Methods inherited from class confidenceMachine.ConfidenceClassifier
calculateConfidenceAndCredibility, calculatePValue, calculatePValue, classifyInstance, returnRegionPrediction
 
Methods inherited from class weka.classifiers.Classifier
debugTipText, distributionForInstance, forName, getDebug, makeCopies, setDebug
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TCMKNearestNeighbours

public TCMKNearestNeighbours(int k)
The amazing TCM K Nearest Neighbours classifier

Parameters:
k - the number of nearest neighbors to use for prediction

TCMKNearestNeighbours

public TCMKNearestNeighbours()
The amazing TCM K Nearest Neighbours classifier

Method Detail

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
Updates the classifier.

Specified by:
updateClassifier in interface UpdateableClassifier
Parameters:
instance - the instance to be put into the classifier
Throws:
java.lang.Exception - if the instance could not be included successfully

setKNN

public void setKNN(int k)
Set the number of neighbours the learner is to use.

Parameters:
k - the number of neighbours.

getKNN

public int getKNN()
Gets the number of neighbours the learner will use.

Returns:
the number of neighbours.

setDebugEvery

public void setDebugEvery(int debug)
Set the TCM to debug its output, outputting progress as it goes along. (Maybe also output alphas?) This is very useful when processing very large data sets, to keep track of its progress (defualt: -1) which specifies no output at all.


getDebugEvery

public int getDebugEvery()
Reports whether the TCM is currently in debug mode (if not -1), and specifies how frequently to output message about TCM's progress on data.

Returns:
how fre

setDistanceMetric

public boolean setDistanceMetric(java.lang.String distName,
                                 java.lang.String[] distOptions)
Set the distance metric

Parameters:
distName - the distance metric class name in full
distOptions - the options specified for that distance metric
Returns:
true if successful

getDistanceMetric

public java.lang.String getDistanceMetric()
The gives details about the distance metric that has been chosen

Returns:
true if default Euclidean chosen, false other wise

listOptions

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

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

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

Specified by:
setOptions in interface OptionHandler
Overrides:
setOptions in class Classifier
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 TCM.

Specified by:
getOptions in interface OptionHandler
Overrides:
getOptions in class Classifier
Returns:
an array of strings suitable for passing to setOptions()

pValuesForInstance

public double[] pValuesForInstance(Instance instance)
                            throws java.lang.Exception
Returns the p-values for a given test instance.

Specified by:
pValuesForInstance in class ConfidenceClassifier
Parameters:
instance - the instance to be classified
Returns:
the probabilities for each class (normalised p-values)
Throws:
java.lang.Exception - no training instances

toString

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

Overrides:
toString in class java.lang.Object
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 - should contain command line arguments for evaluation (see Evaluation).


Copyright (c) 2003 David Lindsay, Computer Learning Research Centre, Dept. Computer Science, Royal Holloway, University of London