类 IBk
java.lang.Object
weka.classifiers.Classifier
weka.classifiers.lazy.IBk
- 所有已实现的接口:
Serializable
,Cloneable
,UpdateableClassifier
,AdditionalMeasureProducer
,CapabilitiesHandler
,OptionHandler
,RevisionHandler
,TechnicalInformationHandler
,WeightedInstancesHandler
public class IBk
extends Classifier
implements OptionHandler, UpdateableClassifier, WeightedInstancesHandler, TechnicalInformationHandler, AdditionalMeasureProducer
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. BibTeX:
For more information, see
D. Aha, D. Kibler (1991). Instance-based learning algorithms. Machine Learning. 6:37-66. BibTeX:
@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).
- 版本:
- $Revision: 10069 $
- 作者:
- Stuart Inglis (singlis@cs.waikato.ac.nz), Len Trigg (trigg@cs.waikato.ac.nz), Eibe Frank (eibe@cs.waikato.ac.nz)
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明static final Tag[]
possible instance weighting methods.static final int
weight by 1/distance.static final int
no weighting.static final int
weight by 1-distance. -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明void
buildClassifier
(Instances instances) Generates the classifier.Returns the tip text for this property.Returns the tip text for this property.double[]
distributionForInstance
(Instance instance) Calculates the class membership probabilities for the given test instance.Returns an enumeration of the additional measure names produced by the neighbour search algorithm, plus the chosen K in case cross-validation is enabled.Returns default capabilities of the classifier.boolean
Gets whether hold-one-out cross-validation will be used to select the best k value.Gets the distance weighting method used.int
getKNN()
Gets the number of neighbours the learner will use.boolean
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.Returns the current nearestNeighbourSearch algorithm in use.int
Get the number of training instances the classifier is currently using.String[]
Gets the current settings of IBk.Returns the revision string.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
Gets the maximum number of instances allowed in the training pool.Returns a string describing classifier.Returns the tip text for this property.Returns an enumeration describing the available options.static void
Main method for testing this class.Returns the tip text for this property.Returns the tip text for this property.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.toString()
Returns a description of this classifier.void
updateClassifier
(Instance instance) Adds the supplied instance to the training set.Returns the tip text for this property.从类继承的方法 weka.classifiers.Classifier
classifyInstance, debugTipText, forName, getDebug, makeCopies, makeCopy, setDebug
-
字段详细资料
-
WEIGHT_NONE
public static final int WEIGHT_NONEno weighting.- 另请参阅:
-
WEIGHT_INVERSE
public static final int WEIGHT_INVERSEweight by 1/distance.- 另请参阅:
-
WEIGHT_SIMILARITY
public static final int WEIGHT_SIMILARITYweight by 1-distance.- 另请参阅:
-
TAGS_WEIGHTING
possible instance weighting methods.
-
-
构造器详细资料
-
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.- 参数:
k
- the number of nearest neighbors to use for prediction
-
IBk
public IBk()IB1 classifer. Instance-based learner. Predicts the class of the single nearest training instance for each test instance.
-
-
方法详细资料
-
globalInfo
Returns a string describing classifier.- 返回:
- a description suitable for displaying in the explorer/experimenter gui
-
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.- 指定者:
getTechnicalInformation
在接口中TechnicalInformationHandler
- 返回:
- the technical information about this class
-
KNNTipText
Returns the tip text for this property.- 返回:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setKNN
public void setKNN(int k) Set the number of neighbours the learner is to use.- 参数:
k
- the number of neighbours.
-
getKNN
public int getKNN()Gets the number of neighbours the learner will use.- 返回:
- the number of neighbours.
-
windowSizeTipText
Returns the tip text for this property.- 返回:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
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.- 返回:
- Value of WindowSize.
-
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.- 参数:
newWindowSize
- Value to assign to WindowSize.
-
distanceWeightingTipText
Returns the tip text for this property.- 返回:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getDistanceWeighting
Gets the distance weighting method used. Will be one of WEIGHT_NONE, WEIGHT_INVERSE, or WEIGHT_SIMILARITY- 返回:
- the distance weighting method used.
-
setDistanceWeighting
Sets the distance weighting method used. Values other than WEIGHT_NONE, WEIGHT_INVERSE, or WEIGHT_SIMILARITY will be ignored.- 参数:
newMethod
- the distance weighting method to use
-
meanSquaredTipText
Returns the tip text for this property.- 返回:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getMeanSquared
public boolean getMeanSquared()Gets whether the mean squared error is used rather than mean absolute error when doing cross-validation.- 返回:
- true if so.
-
setMeanSquared
public void setMeanSquared(boolean newMeanSquared) Sets whether the mean squared error is used rather than mean absolute error when doing cross-validation.- 参数:
newMeanSquared
- true if so.
-
crossValidateTipText
Returns the tip text for this property.- 返回:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getCrossValidate
public boolean getCrossValidate()Gets whether hold-one-out cross-validation will be used to select the best k value.- 返回:
- true if cross-validation will be used.
-
setCrossValidate
public void setCrossValidate(boolean newCrossValidate) Sets whether hold-one-out cross-validation will be used to select the best k value.- 参数:
newCrossValidate
- true if cross-validation should be used.
-
nearestNeighbourSearchAlgorithmTipText
Returns the tip text for this property.- 返回:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getNearestNeighbourSearchAlgorithm
Returns the current nearestNeighbourSearch algorithm in use.- 返回:
- the NearestNeighbourSearch algorithm currently in use.
-
setNearestNeighbourSearchAlgorithm
public void setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch nearestNeighbourSearchAlgorithm) Sets the nearestNeighbourSearch algorithm to be used for finding nearest neighbour(s).- 参数:
nearestNeighbourSearchAlgorithm
- - The NearestNeighbourSearch class.
-
getNumTraining
public int getNumTraining()Get the number of training instances the classifier is currently using.- 返回:
- the number of training instances the classifier is currently using
-
getCapabilities
Returns default capabilities of the classifier.- 指定者:
getCapabilities
在接口中CapabilitiesHandler
- 覆盖:
getCapabilities
在类中Classifier
- 返回:
- the capabilities of this classifier
- 另请参阅:
-
buildClassifier
Generates the classifier.- 指定者:
buildClassifier
在类中Classifier
- 参数:
instances
- set of instances serving as training data- 抛出:
Exception
- if the classifier has not been generated successfully
-
updateClassifier
Adds the supplied instance to the training set.- 指定者:
updateClassifier
在接口中UpdateableClassifier
- 参数:
instance
- the instance to add- 抛出:
Exception
- if instance could not be incorporated successfully
-
distributionForInstance
Calculates the class membership probabilities for the given test instance.- 覆盖:
distributionForInstance
在类中Classifier
- 参数:
instance
- the instance to be classified- 返回:
- predicted class probability distribution
- 抛出:
Exception
- if an error occurred during the prediction
-
listOptions
Returns an enumeration describing the available options.- 指定者:
listOptions
在接口中OptionHandler
- 覆盖:
listOptions
在类中Classifier
- 返回:
- an enumeration of all the available options.
-
setOptions
Parses a given list of options. 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).
- 指定者:
setOptions
在接口中OptionHandler
- 覆盖:
setOptions
在类中Classifier
- 参数:
options
- the list of options as an array of strings- 抛出:
Exception
- if an option is not supported
-
getOptions
Gets the current settings of IBk.- 指定者:
getOptions
在接口中OptionHandler
- 覆盖:
getOptions
在类中Classifier
- 返回:
- an array of strings suitable for passing to setOptions()
-
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.- 指定者:
enumerateMeasures
在接口中AdditionalMeasureProducer
- 返回:
- an enumeration of the measure names
-
getMeasure
Returns the value of the named measure from the neighbour search algorithm, plus the chosen K in case cross-validation is enabled.- 指定者:
getMeasure
在接口中AdditionalMeasureProducer
- 参数:
additionalMeasureName
- the name of the measure to query for its value- 返回:
- the value of the named measure
- 抛出:
IllegalArgumentException
- if the named measure is not supported
-
toString
Returns a description of this classifier. -
pruneToK
Prunes the list to contain the k nearest neighbors. If there are multiple neighbors at the k'th distance, all will be kept.- 参数:
neighbours
- the neighbour instances.distances
- the distances of the neighbours from target instance.k
- the number of neighbors to keep.- 返回:
- the pruned neighbours.
-
getRevision
Returns the revision string.- 指定者:
getRevision
在接口中RevisionHandler
- 覆盖:
getRevision
在类中Classifier
- 返回:
- the revision
-
main
Main method for testing this class.- 参数:
argv
- should contain command line options (see setOptions)
-