Help Topics Concepts Package Class

## k-NN Bean Properties and Use

### Properties

k parameter
  Represents the number of neighbors the algorithm is looking at in order to decide the class for a new example. Can be set between different runs of the algorithm until an optimal value is found for a particular data set.
numAttributes
  Represents the number of attributes. This property is set when the knn bean is created based on the data in the input file, and cannot be changed later.
numClasses
  Represents the possible classes for a particular data set. This property is set when the knn bean is created based on the data in the input file, and cannot be changed later.
numRecords
  Represents the number of records in the input file. This property is set when the knn bean is created based on the data in the input file, and cannot be changed later.
Mode
  Select one of the following agent modes:
  Train implies that the data is read from the Import corresponding to the input file and stored in the knn model.
  Test implies that the knn model is used to classify new data and compute the accuracy of classification based on known labels of test data. The optimal k value for a particular data can be found in this mode, based on the accuracy observed.
  Run implies that the model is used to classify new data as it is process. No feedback about accuracy can be given in this case, as the correct labels are not known.

### Use

The knn Bean panel is used to create a knn classifier with the specified parameters. The Mode should be set only to test or run values once the input data has been stored in the model.

After the data is stored, the mode is automatically set to test. It can be changed manually to run. The k parameter can also be manually changed.

Steps in using the knn panel include:

1. Set the mode and k, if necessary. Press the OK button to apply changes.
2. Create inspectors on the inspectable properties (inputBuffer, outputBuffer, accuracy, error etc.).
3. Optionally connect another Import Bean if you wish to use independent data for testing.
4. Press the Step button on the Agent Editor toolbar and view the input data and knn result in the inspectors, or
5. Press the Cycle button on the AgentEditor to cycle through all the examples in the test set.
6. Inspect the desired properties (e.g. accuracy) and change k if the current value is not satisfactory. Any time when the end of the test file is read, some of the properties of the bean are reset to their default values (e.g. accuracy, number of correctly classified examples etc.) and the algorithm starts over.

In run mode, data is processed similar to test but statistical properties like accuracy and error are not calculated.

If you press the Reset button, you reset the bean's statistics such as total number of examples processed, number of correctly classified examples, accuracy and error.