public class IBk extends Classifier implements OptionHandler, UpdateableClassifier, WeightedInstancesHandler, TechnicalInformationHandler, AdditionalMeasureProducer
@article{Aha1991, author = {D. Aha and D. Kibler}, journal = {Machine Learning}, pages = {37-66}, title = {Instance-based learning algorithms}, volume = {6}, year = {1991} }Valid options are:
-I Weight neighbours by the inverse of their distance (use when k > 1)
-F Weight neighbours by 1 - their distance (use when k > 1)
-K <number of neighbors> Number of nearest neighbours (k) used in classification. (Default = 1)
-E Minimise mean squared error rather than mean absolute error when using -X option with numeric prediction.
-W <window size> Maximum number of training instances maintained. Training instances are dropped FIFO. (Default = no window)
-X Select the number of nearest neighbours between 1 and the k value specified using hold-one-out evaluation on the training data (use when k > 1)
-A The nearest neighbour search algorithm to use (default: weka.core.neighboursearch.LinearNNSearch).
Modifier and Type | Field and Description |
---|---|
static Tag[] |
TAGS_WEIGHTING
possible instance weighting methods.
|
static int |
WEIGHT_INVERSE
weight by 1/distance.
|
static int |
WEIGHT_NONE
no weighting.
|
static int |
WEIGHT_SIMILARITY
weight by 1-distance.
|
Constructor and Description |
---|
IBk()
IB1 classifer.
|
IBk(int k)
IBk classifier.
|
Modifier and Type | Method and Description |
---|---|
void |
buildClassifier(Instances instances)
Generates the classifier.
|
java.lang.String |
crossValidateTipText()
Returns the tip text for this property.
|
java.lang.String |
distanceWeightingTipText()
Returns the tip text for this property.
|
double[] |
distributionForInstance(Instance instance)
Calculates the class membership probabilities for the given test instance.
|
java.util.Enumeration |
enumerateMeasures()
Returns an enumeration of the additional measure names
produced by the neighbour search algorithm, plus the chosen K in case
cross-validation is enabled.
|
Capabilities |
getCapabilities()
Returns default capabilities of the classifier.
|
boolean |
getCrossValidate()
Gets whether hold-one-out cross-validation will be used
to select the best k value.
|
SelectedTag |
getDistanceWeighting()
Gets the distance weighting method used.
|
int |
getKNN()
Gets the number of neighbours the learner will use.
|
boolean |
getMeanSquared()
Gets whether the mean squared error is used rather than mean
absolute error when doing cross-validation.
|
double |
getMeasure(java.lang.String additionalMeasureName)
Returns the value of the named measure from the
neighbour search algorithm, plus the chosen K in case
cross-validation is enabled.
|
NearestNeighbourSearch |
getNearestNeighbourSearchAlgorithm()
Returns the current nearestNeighbourSearch algorithm in use.
|
int |
getNumTraining()
Get the number of training instances the classifier is currently using.
|
java.lang.String[] |
getOptions()
Gets the current settings of IBk.
|
java.lang.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 |
getWindowSize()
Gets the maximum number of instances allowed in the training
pool.
|
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.
|
java.lang.String |
meanSquaredTipText()
Returns the tip text for this property.
|
java.lang.String |
nearestNeighbourSearchAlgorithmTipText()
Returns the tip text for this property.
|
Instances |
pruneToK(Instances neighbours,
double[] distances,
int k)
Prunes the list to contain the k nearest neighbors.
|
void |
setCrossValidate(boolean newCrossValidate)
Sets whether hold-one-out cross-validation will be used
to select the best k value.
|
void |
setDistanceWeighting(SelectedTag newMethod)
Sets the distance weighting method used.
|
void |
setKNN(int k)
Set the number of neighbours the learner is to use.
|
void |
setMeanSquared(boolean newMeanSquared)
Sets whether the mean squared error is used rather than mean
absolute error when doing cross-validation.
|
void |
setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch nearestNeighbourSearchAlgorithm)
Sets the nearestNeighbourSearch algorithm to be used for finding nearest
neighbour(s).
|
void |
setOptions(java.lang.String[] options)
Parses a given list of options.
|
void |
setWindowSize(int newWindowSize)
Sets the maximum number of instances allowed in the training
pool.
|
java.lang.String |
toString()
Returns a description of this classifier.
|
void |
updateClassifier(Instance instance)
Adds the supplied instance to the training set.
|
java.lang.String |
windowSizeTipText()
Returns the tip text for this property.
|
classifyInstance, debugTipText, forName, getDebug, makeCopies, makeCopy, setDebug
public static final int WEIGHT_NONE
public static final int WEIGHT_INVERSE
public static final int WEIGHT_SIMILARITY
public static final Tag[] TAGS_WEIGHTING
public IBk(int k)
k
- the number of nearest neighbors to use for predictionpublic IBk()
public java.lang.String globalInfo()
public TechnicalInformation getTechnicalInformation()
getTechnicalInformation
in interface TechnicalInformationHandler
public java.lang.String KNNTipText()
public void setKNN(int k)
k
- the number of neighbours.public int getKNN()
public java.lang.String windowSizeTipText()
public int getWindowSize()
public void setWindowSize(int newWindowSize)
newWindowSize
- Value to assign to WindowSize.public java.lang.String distanceWeightingTipText()
public SelectedTag getDistanceWeighting()
public void setDistanceWeighting(SelectedTag newMethod)
newMethod
- the distance weighting method to usepublic java.lang.String meanSquaredTipText()
public boolean getMeanSquared()
public void setMeanSquared(boolean newMeanSquared)
newMeanSquared
- true if so.public java.lang.String crossValidateTipText()
public boolean getCrossValidate()
public void setCrossValidate(boolean newCrossValidate)
newCrossValidate
- true if cross-validation should be used.public java.lang.String nearestNeighbourSearchAlgorithmTipText()
public NearestNeighbourSearch getNearestNeighbourSearchAlgorithm()
public void setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch nearestNeighbourSearchAlgorithm)
nearestNeighbourSearchAlgorithm
- - The NearestNeighbourSearch class.public int getNumTraining()
public Capabilities getCapabilities()
getCapabilities
in interface CapabilitiesHandler
getCapabilities
in class Classifier
Capabilities
public void buildClassifier(Instances instances) throws java.lang.Exception
buildClassifier
in class Classifier
instances
- set of instances serving as training datajava.lang.Exception
- if the classifier has not been generated successfullypublic void updateClassifier(Instance instance) throws java.lang.Exception
updateClassifier
in interface UpdateableClassifier
instance
- the instance to addjava.lang.Exception
- if instance could not be incorporated
successfullypublic double[] distributionForInstance(Instance instance) throws java.lang.Exception
distributionForInstance
in class Classifier
instance
- the instance to be classifiedjava.lang.Exception
- if an error occurred during the predictionpublic java.util.Enumeration listOptions()
listOptions
in interface OptionHandler
listOptions
in class Classifier
public void setOptions(java.lang.String[] options) throws java.lang.Exception
-I Weight neighbours by the inverse of their distance (use when k > 1)
-F Weight neighbours by 1 - their distance (use when k > 1)
-K <number of neighbors> Number of nearest neighbours (k) used in classification. (Default = 1)
-E Minimise mean squared error rather than mean absolute error when using -X option with numeric prediction.
-W <window size> Maximum number of training instances maintained. Training instances are dropped FIFO. (Default = no window)
-X Select the number of nearest neighbours between 1 and the k value specified using hold-one-out evaluation on the training data (use when k > 1)
-A The nearest neighbour search algorithm to use (default: weka.core.neighboursearch.LinearNNSearch).
setOptions
in interface OptionHandler
setOptions
in class Classifier
options
- the list of options as an array of stringsjava.lang.Exception
- if an option is not supportedpublic java.lang.String[] getOptions()
getOptions
in interface OptionHandler
getOptions
in class Classifier
public java.util.Enumeration enumerateMeasures()
enumerateMeasures
in interface AdditionalMeasureProducer
public double getMeasure(java.lang.String additionalMeasureName)
getMeasure
in interface AdditionalMeasureProducer
additionalMeasureName
- the name of the measure to query for its valuejava.lang.IllegalArgumentException
- if the named measure is not supportedpublic java.lang.String toString()
toString
in class java.lang.Object
public Instances pruneToK(Instances neighbours, double[] distances, int k)
neighbours
- the neighbour instances.distances
- the distances of the neighbours from target instance.k
- the number of neighbors to keep.public java.lang.String getRevision()
getRevision
in interface RevisionHandler
getRevision
in class Classifier
public static void main(java.lang.String[] argv)
argv
- should contain command line options (see setOptions)