Help Topics Concepts Package Class

## k-NN Classifier Agent Properties and Use

### Properties

The k-NN Classifier Agent panel provides these options:

Training File Name
  Enter the name of a definition file. Use the Browse button to select a definition file. This file will be used to specify some knn parameters, such as number of attributes/fields present in each example, number of possible classes, and number of records in the input file. One of the fields must have a field name of class to support supervised learning. The data itself must be a file by the same name with a .dat extension. This will be used when the mode is Train and also to Generate Beans.
Testing File Name
  Enter the name of a definition file with the same layout as the training definition file. Use the Browse button to select a definition file. This will be used when you set the mode to Test or Run.

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.
Agent 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 k-NN Classifier Agent panel is used to generate an agent containing import beans for training and testing, a knn bean, filter beans to translate knn inputs and outputs, and data connections. The Agent Mode is set so that the knn bean can be trained (data is stored in the knn model), test or run on a different test file.

Steps in using the knn classifier agent include:

1. Enter the name of the training file that defines the record layout and name of the training data source. If the file is read successfully, the Generate Beans button should be enabled.
2. Select Train for the Agent Mode.
3. Set the k value.
4. Press the Generate Beans button. The Reset button should now be enabled. Also the mode should be set to test because training data was already stored in the knn model.
5. Change the mode to run if necessary..
6. Press OK button to set the changed values.
7. At some point you may wish to press the Reset Beans button to re-initialize all the beans to their initial default values.