public class IBk extends AbstractClassifier 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.
|
String |
crossValidateTipText()
Returns the tip text for this property.
|
String |
distanceWeightingTipText()
Returns the tip text for this property.
|
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, 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(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.
|
String[] |
getOptions()
Gets the current settings of IBk.
|
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.
|
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 |
meanSquaredTipText()
Returns the tip text for this property.
|
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(String[] options)
Parses a given list of options.
|
void |
setWindowSize(int newWindowSize)
Sets the maximum number of instances allowed in the training
pool.
|
String |
toString()
Returns a description of this classifier.
|
void |
updateClassifier(Instance instance)
Adds the supplied instance to the training set.
|
String |
windowSizeTipText()
Returns the tip text for this property.
|
classifyInstance, debugTipText, forName, getDebug, makeCopies, makeCopy, runClassifier, 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 String globalInfo()
public TechnicalInformation getTechnicalInformation()
getTechnicalInformation
in interface TechnicalInformationHandler
public String KNNTipText()
public void setKNN(int k)
k
- the number of neighbours.public int getKNN()
public String windowSizeTipText()
public int getWindowSize()
public void setWindowSize(int newWindowSize)
newWindowSize
- Value to assign to WindowSize.public String distanceWeightingTipText()
public SelectedTag getDistanceWeighting()
public void setDistanceWeighting(SelectedTag newMethod)
newMethod
- the distance weighting method to usepublic String meanSquaredTipText()
public boolean getMeanSquared()
public void setMeanSquared(boolean newMeanSquared)
newMeanSquared
- true if so.public String crossValidateTipText()
public boolean getCrossValidate()
public void setCrossValidate(boolean newCrossValidate)
newCrossValidate
- true if cross-validation should be used.public String nearestNeighbourSearchAlgorithmTipText()
public NearestNeighbourSearch getNearestNeighbourSearchAlgorithm()
public void setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch nearestNeighbourSearchAlgorithm)
nearestNeighbourSearchAlgorithm
- - The NearestNeighbourSearch class.public int getNumTraining()
public Capabilities getCapabilities()
getCapabilities
in interface Classifier
getCapabilities
in interface CapabilitiesHandler
getCapabilities
in class AbstractClassifier
Capabilities
public void buildClassifier(Instances instances) throws Exception
buildClassifier
in interface Classifier
instances
- set of instances serving as training dataException
- if the classifier has not been generated successfullypublic void updateClassifier(Instance instance) throws Exception
updateClassifier
in interface UpdateableClassifier
instance
- the instance to addException
- if instance could not be incorporated
successfullypublic double[] distributionForInstance(Instance instance) throws Exception
distributionForInstance
in interface Classifier
distributionForInstance
in class AbstractClassifier
instance
- the instance to be classifiedException
- if an error occurred during the predictionpublic Enumeration listOptions()
listOptions
in interface OptionHandler
listOptions
in class AbstractClassifier
public void setOptions(String[] options) throws 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 AbstractClassifier
options
- the list of options as an array of stringsException
- if an option is not supportedpublic String[] getOptions()
getOptions
in interface OptionHandler
getOptions
in class AbstractClassifier
public Enumeration enumerateMeasures()
enumerateMeasures
in interface AdditionalMeasureProducer
public double getMeasure(String additionalMeasureName)
getMeasure
in interface AdditionalMeasureProducer
additionalMeasureName
- the name of the measure to query for its valueIllegalArgumentException
- if the named measure is not supportedpublic String toString()
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 String getRevision()
getRevision
in interface RevisionHandler
getRevision
in class AbstractClassifier
public static void main(String[] argv)
argv
- should contain command line options (see setOptions)Copyright © 2012 University of Waikato, Hamilton, NZ. All Rights Reserved.