|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectweka.classifiers.Classifier
weka.classifiers.lazy.IBk
public class IBk
K-nearest neighbours classifier. Can select appropriate value of K based on cross-validation. Can also do distance weighting.
For more information, see
D. Aha, D. Kibler (1991). Instance-based learning algorithms. Machine Learning. 6:37-66.
@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).
| Field Summary | |
|---|---|
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 Summary | |
|---|---|
IBk()
IB1 classifer. |
|
IBk(int k)
IBk classifier. |
|
| Method Summary | |
|---|---|
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. |
| 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 |
| Field Detail |
|---|
public static final int WEIGHT_NONE
public static final int WEIGHT_INVERSE
public static final int WEIGHT_SIMILARITY
public static final Tag[] TAGS_WEIGHTING
| Constructor Detail |
|---|
public IBk(int k)
k - the number of nearest neighbors to use for predictionpublic IBk()
| Method Detail |
|---|
public java.lang.String globalInfo()
public TechnicalInformation getTechnicalInformation()
getTechnicalInformation in interface TechnicalInformationHandlerpublic 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 CapabilitiesHandlergetCapabilities in class ClassifierCapabilities
public void buildClassifier(Instances instances)
throws java.lang.Exception
buildClassifier in class Classifierinstances - set of instances serving as training data
java.lang.Exception - if the classifier has not been generated successfully
public void updateClassifier(Instance instance)
throws java.lang.Exception
updateClassifier in interface UpdateableClassifierinstance - the instance to add
java.lang.Exception - if instance could not be incorporated
successfully
public double[] distributionForInstance(Instance instance)
throws java.lang.Exception
distributionForInstance in class Classifierinstance - the instance to be classified
java.lang.Exception - if an error occurred during the predictionpublic java.util.Enumeration listOptions()
listOptions in interface OptionHandlerlistOptions 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 OptionHandlersetOptions in class Classifieroptions - the list of options as an array of strings
java.lang.Exception - if an option is not supportedpublic java.lang.String[] getOptions()
getOptions in interface OptionHandlergetOptions in class Classifierpublic java.util.Enumeration enumerateMeasures()
enumerateMeasures in interface AdditionalMeasureProducerpublic double getMeasure(java.lang.String additionalMeasureName)
getMeasure in interface AdditionalMeasureProduceradditionalMeasureName - the name of the measure to query for its value
java.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 RevisionHandlergetRevision in class Classifierpublic static void main(java.lang.String[] argv)
argv - should contain command line options (see setOptions)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||