Java Doc for IBk.java in  » Science » weka » weka » classifiers » lazy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » weka » weka.classifiers.lazy 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   weka.classifiers.Classifier
      weka.classifiers.lazy.IBk

IBk
public class IBk extends Classifier implements OptionHandler,UpdateableClassifier,WeightedInstancesHandler,TechnicalInformationHandler,AdditionalMeasureProducer(Code)
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:

 @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).
 

author:
   Stuart Inglis (singlis@cs.waikato.ac.nz)
author:
   Len Trigg (trigg@cs.waikato.ac.nz)
author:
   Eibe Frank (eibe@cs.waikato.ac.nz)
version:
   $Revision: 1.40 $


Field Summary
final public static  Tag[]TAGS_WEIGHTING
     possible instance weighting methods.
final public static  intWEIGHT_INVERSE
     weight by 1/distance.
final public static  intWEIGHT_NONE
     no weighting.
final public static  intWEIGHT_SIMILARITY
     weight by 1-distance.
protected  intm_ClassType
     The class attribute type.
protected  booleanm_CrossValidate
     Whether to select k by cross validation.
protected  intm_DistanceWeighting
     Whether the neighbours should be distance-weighted.
protected  booleanm_MeanSquared
     Whether to minimise mean squared error rather than mean absolute error when cross-validating on numeric prediction tasks.
protected  NearestNeighbourSearchm_NNSearch
     for nearest-neighbor search.
protected  doublem_NumAttributesUsed
     The number of attributes the contribute to a prediction.
protected  intm_NumClasses
     The number of class values (or 1 if predicting numeric).
protected  Instancesm_Train
     The training instances used for classification.
protected  intm_WindowSize
     The maximum number of training instances allowed.
protected  intm_kNN
     The number of neighbours to use for classification (currently).
protected  intm_kNNUpper
     The value of kNN provided by the user.
protected  booleanm_kNNValid
     Whether the value of k selected by cross validation has been invalidated by a change in the training instances.
final static  longserialVersionUID
     for serialization.

Constructor Summary
public  IBk(int k)
     IBk classifier.
public  IBk()
     IB1 classifer.

Method Summary
public  StringKNNTipText()
     Returns the tip text for this property.
public  voidbuildClassifier(Instances instances)
     Generates the classifier.
protected  voidcrossValidate()
     Select the best value for k by hold-one-out cross-validation. If the class attribute is nominal, classification error is minimised.
public  StringcrossValidateTipText()
     Returns the tip text for this property.
public  StringdistanceWeightingTipText()
     Returns the tip text for this property.
public  double[]distributionForInstance(Instance instance)
     Calculates the class membership probabilities for the given test instance.
public  EnumerationenumerateMeasures()
     Returns an enumeration of the additional measure names produced by the neighbour search algorithm.
public  CapabilitiesgetCapabilities()
     Returns default capabilities of the classifier.
public  booleangetCrossValidate()
     Gets whether hold-one-out cross-validation will be used to select the best k value.
public  SelectedTaggetDistanceWeighting()
     Gets the distance weighting method used.
public  intgetKNN()
     Gets the number of neighbours the learner will use.
public  booleangetMeanSquared()
     Gets whether the mean squared error is used rather than mean absolute error when doing cross-validation.
public  doublegetMeasure(String additionalMeasureName)
     Returns the value of the named measure from the neighbour search algorithm.
public  NearestNeighbourSearchgetNearestNeighbourSearchAlgorithm()
     Returns the current nearestNeighbourSearch algorithm in use.
public  intgetNumTraining()
     Get the number of training instances the classifier is currently using.
public  String[]getOptions()
     Gets the current settings of IBk.
public  TechnicalInformationgetTechnicalInformation()
     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.
public  intgetWindowSize()
     Gets the maximum number of instances allowed in the training pool.
public  StringglobalInfo()
     Returns a string describing classifier.
protected  voidinit()
     Initialise scheme variables.
public  EnumerationlistOptions()
     Returns an enumeration describing the available options.
public static  voidmain(String[] argv)
     Main method for testing this class.
protected  double[]makeDistribution(Instances neighbours, double[] distances)
     Turn the list of nearest neighbors into a probability distribution.
public  StringmeanSquaredTipText()
     Returns the tip text for this property.
public  StringnearestNeighbourSearchAlgorithmTipText()
     Returns the tip text for this property.
public  InstancespruneToK(Instances neighbours, double[] distances, int k)
     Prunes the list to contain the k nearest neighbors.
public  voidsetCrossValidate(boolean newCrossValidate)
     Sets whether hold-one-out cross-validation will be used to select the best k value.
public  voidsetDistanceWeighting(SelectedTag newMethod)
     Sets the distance weighting method used.
public  voidsetKNN(int k)
     Set the number of neighbours the learner is to use.
public  voidsetMeanSquared(boolean newMeanSquared)
     Sets whether the mean squared error is used rather than mean absolute error when doing cross-validation.
public  voidsetNearestNeighbourSearchAlgorithm(NearestNeighbourSearch nearestNeighbourSearchAlgorithm)
     Sets the nearestNeighbourSearch algorithm to be used for finding nearest neighbour(s).
public  voidsetOptions(String[] options)
     Parses a given list of options.
public  voidsetWindowSize(int newWindowSize)
     Sets the maximum number of instances allowed in the training pool.
public  StringtoString()
     Returns a description of this classifier.
public  voidupdateClassifier(Instance instance)
     Adds the supplied instance to the training set.
public  StringwindowSizeTipText()
     Returns the tip text for this property.

Field Detail
TAGS_WEIGHTING
final public static Tag[] TAGS_WEIGHTING(Code)
possible instance weighting methods.



WEIGHT_INVERSE
final public static int WEIGHT_INVERSE(Code)
weight by 1/distance.



WEIGHT_NONE
final public static int WEIGHT_NONE(Code)
no weighting.



WEIGHT_SIMILARITY
final public static int WEIGHT_SIMILARITY(Code)
weight by 1-distance.



m_ClassType
protected int m_ClassType(Code)
The class attribute type.



m_CrossValidate
protected boolean m_CrossValidate(Code)
Whether to select k by cross validation.



m_DistanceWeighting
protected int m_DistanceWeighting(Code)
Whether the neighbours should be distance-weighted.



m_MeanSquared
protected boolean m_MeanSquared(Code)
Whether to minimise mean squared error rather than mean absolute error when cross-validating on numeric prediction tasks.



m_NNSearch
protected NearestNeighbourSearch m_NNSearch(Code)
for nearest-neighbor search.



m_NumAttributesUsed
protected double m_NumAttributesUsed(Code)
The number of attributes the contribute to a prediction.



m_NumClasses
protected int m_NumClasses(Code)
The number of class values (or 1 if predicting numeric).



m_Train
protected Instances m_Train(Code)
The training instances used for classification.



m_WindowSize
protected int m_WindowSize(Code)
The maximum number of training instances allowed. When this limit is reached, old training instances are removed, so the training data is "windowed". Set to 0 for unlimited numbers of instances.



m_kNN
protected int m_kNN(Code)
The number of neighbours to use for classification (currently).



m_kNNUpper
protected int m_kNNUpper(Code)
The value of kNN provided by the user. This may differ from m_kNN if cross-validation is being used.



m_kNNValid
protected boolean m_kNNValid(Code)
Whether the value of k selected by cross validation has been invalidated by a change in the training instances.



serialVersionUID
final static long serialVersionUID(Code)
for serialization.




Constructor Detail
IBk
public IBk(int k)(Code)
IBk classifier. Simple instance-based learner that uses the class of the nearest k training instances for the class of the test instances.
Parameters:
  k - the number of nearest neighbors to use for prediction



IBk
public IBk()(Code)
IB1 classifer. Instance-based learner. Predicts the class of the single nearest training instance for each test instance.




Method Detail
KNNTipText
public String KNNTipText()(Code)
Returns the tip text for this property. tip text for this property suitable fordisplaying in the explorer/experimenter gui



buildClassifier
public void buildClassifier(Instances instances) throws Exception(Code)
Generates the classifier.
Parameters:
  instances - set of instances serving as training data
throws:
  Exception - if the classifier has not been generated successfully



crossValidate
protected void crossValidate()(Code)
Select the best value for k by hold-one-out cross-validation. If the class attribute is nominal, classification error is minimised. If the class attribute is numeric, mean absolute error is minimised



crossValidateTipText
public String crossValidateTipText()(Code)
Returns the tip text for this property. tip text for this property suitable fordisplaying in the explorer/experimenter gui



distanceWeightingTipText
public String distanceWeightingTipText()(Code)
Returns the tip text for this property. tip text for this property suitable fordisplaying in the explorer/experimenter gui



distributionForInstance
public double[] distributionForInstance(Instance instance) throws Exception(Code)
Calculates the class membership probabilities for the given test instance.
Parameters:
  instance - the instance to be classified predicted class probability distribution
throws:
  Exception - if an error occurred during the prediction



enumerateMeasures
public Enumeration enumerateMeasures()(Code)
Returns an enumeration of the additional measure names produced by the neighbour search algorithm. an enumeration of the measure names



getCapabilities
public Capabilities getCapabilities()(Code)
Returns default capabilities of the classifier. the capabilities of this classifier



getCrossValidate
public boolean getCrossValidate()(Code)
Gets whether hold-one-out cross-validation will be used to select the best k value. true if cross-validation will be used.



getDistanceWeighting
public SelectedTag getDistanceWeighting()(Code)
Gets the distance weighting method used. Will be one of WEIGHT_NONE, WEIGHT_INVERSE, or WEIGHT_SIMILARITY the distance weighting method used.



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



getMeanSquared
public boolean getMeanSquared()(Code)
Gets whether the mean squared error is used rather than mean absolute error when doing cross-validation. true if so.



getMeasure
public double getMeasure(String additionalMeasureName)(Code)
Returns the value of the named measure from the neighbour search algorithm.
Parameters:
  additionalMeasureName - the name of the measure to query for its value the value of the named measure
throws:
  IllegalArgumentException - if the named measure is not supported



getNearestNeighbourSearchAlgorithm
public NearestNeighbourSearch getNearestNeighbourSearchAlgorithm()(Code)
Returns the current nearestNeighbourSearch algorithm in use. the NearestNeighbourSearch algorithm currently in use.



getNumTraining
public int getNumTraining()(Code)
Get the number of training instances the classifier is currently using. the number of training instances the classifier is currently using



getOptions
public String[] getOptions()(Code)
Gets the current settings of IBk. an array of strings suitable for passing to setOptions()



getTechnicalInformation
public TechnicalInformation getTechnicalInformation()(Code)
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. the technical information about this class



getWindowSize
public int getWindowSize()(Code)
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.



globalInfo
public String globalInfo()(Code)
Returns a string describing classifier. a description suitable fordisplaying in the explorer/experimenter gui



init
protected void init()(Code)
Initialise scheme variables.



listOptions
public Enumeration listOptions()(Code)
Returns an enumeration describing the available options. an enumeration of all the available options.



main
public static void main(String[] argv)(Code)
Main method for testing this class.
Parameters:
  argv - should contain command line options (see setOptions)



makeDistribution
protected double[] makeDistribution(Instances neighbours, double[] distances) throws Exception(Code)
Turn the list of nearest neighbors into a probability distribution.
Parameters:
  neighbours - the list of nearest neighboring instances
Parameters:
  distances - the distances of the neighbors the probability distribution
throws:
  Exception - if computation goes wrong or has no class attribute



meanSquaredTipText
public String meanSquaredTipText()(Code)
Returns the tip text for this property. tip text for this property suitable fordisplaying in the explorer/experimenter gui



nearestNeighbourSearchAlgorithmTipText
public String nearestNeighbourSearchAlgorithmTipText()(Code)
Returns the tip text for this property. tip text for this property suitable fordisplaying in the explorer/experimenter gui



pruneToK
public Instances pruneToK(Instances neighbours, double[] distances, int k)(Code)
Prunes the list to contain the k nearest neighbors. If there are multiple neighbors at the k'th distance, all will be kept.
Parameters:
  neighbours - the neighbour instances.
Parameters:
  distances - the distances of the neighbours from target instance.
Parameters:
  k - the number of neighbors to keep. the pruned neighbours.



setCrossValidate
public void setCrossValidate(boolean newCrossValidate)(Code)
Sets whether hold-one-out cross-validation will be used to select the best k value.
Parameters:
  newCrossValidate - true if cross-validation should be used.



setDistanceWeighting
public void setDistanceWeighting(SelectedTag newMethod)(Code)
Sets the distance weighting method used. Values other than WEIGHT_NONE, WEIGHT_INVERSE, or WEIGHT_SIMILARITY will be ignored.
Parameters:
  newMethod - the distance weighting method to use



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



setMeanSquared
public void setMeanSquared(boolean newMeanSquared)(Code)
Sets whether the mean squared error is used rather than mean absolute error when doing cross-validation.
Parameters:
  newMeanSquared - true if so.



setNearestNeighbourSearchAlgorithm
public void setNearestNeighbourSearchAlgorithm(NearestNeighbourSearch nearestNeighbourSearchAlgorithm)(Code)
Sets the nearestNeighbourSearch algorithm to be used for finding nearest neighbour(s).
Parameters:
  nearestNeighbourSearchAlgorithm - - The NearestNeighbourSearch class.



setOptions
public void setOptions(String[] options) throws Exception(Code)
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).
 

Parameters:
  options - the list of options as an array of strings
throws:
  Exception - if an option is not supported



setWindowSize
public void setWindowSize(int newWindowSize)(Code)
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.
Parameters:
  newWindowSize - Value to assign to WindowSize.



toString
public String toString()(Code)
Returns a description of this classifier. a description of this classifier as a string.



updateClassifier
public void updateClassifier(Instance instance) throws Exception(Code)
Adds the supplied instance to the training set.
Parameters:
  instance - the instance to add
throws:
  Exception - if instance could not be incorporatedsuccessfully



windowSizeTipText
public String windowSizeTipText()(Code)
Returns the tip text for this property. tip text for this property suitable fordisplaying in the explorer/experimenter gui



Fields inherited from weka.classifiers.Classifier
protected boolean m_Debug(Code)(Java Doc)

Methods inherited from weka.classifiers.Classifier
abstract public void buildClassifier(Instances data) throws Exception(Code)(Java Doc)
public double classifyInstance(Instance instance) throws Exception(Code)(Java Doc)
public String debugTipText()(Code)(Java Doc)
public double[] distributionForInstance(Instance instance) throws Exception(Code)(Java Doc)
public static Classifier forName(String classifierName, String[] options) throws Exception(Code)(Java Doc)
public Capabilities getCapabilities()(Code)(Java Doc)
public boolean getDebug()(Code)(Java Doc)
public String[] getOptions()(Code)(Java Doc)
public Enumeration listOptions()(Code)(Java Doc)
public static Classifier[] makeCopies(Classifier model, int num) throws Exception(Code)(Java Doc)
public static Classifier makeCopy(Classifier model) throws Exception(Code)(Java Doc)
protected static void runClassifier(Classifier classifier, String[] options)(Code)(Java Doc)
public void setDebug(boolean debug)(Code)(Java Doc)
public void setOptions(String[] options) throws Exception(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.