ClassesClasses | | Operators

train_class_knnT_train_class_knnTrainClassKnnTrainClassKnn (Operator)


train_class_knnT_train_class_knnTrainClassKnnTrainClassKnn — Creates the search trees for a k-NN classifier.


train_class_knn( : : KNNHandle, GenParamName, GenParamValue : )

Herror T_train_class_knn(const Htuple KNNHandle, const Htuple GenParamName, const Htuple GenParamValue)

void TrainClassKnn(const HTuple& KNNHandle, const HTuple& GenParamName, const HTuple& GenParamValue)

void HClassKnn::TrainClassKnn(const HTuple& GenParamName, const HTuple& GenParamValue) const

static void HOperatorSet.TrainClassKnn(HTuple KNNHandle, HTuple genParamName, HTuple genParamValue)

void HClassKnn.TrainClassKnn(HTuple genParamName, HTuple genParamValue)


train_class_knntrain_class_knnTrainClassKnnTrainClassKnnTrainClassKnn creates the search trees for a k-NN classifier.

It is possible to set the number of trees via the parameters GenParamNameGenParamNameGenParamNameGenParamNamegenParamName and GenParamValueGenParamValueGenParamValueGenParamValuegenParamValue by 'num_trees'"num_trees""num_trees""num_trees""num_trees". The default value for the number of search trees is 4. A higher number of trees improves the accuracy of the search, but increases the run time.

It is possible to add more samples after training using the operator add_sample_class_knnadd_sample_class_knnAddSampleClassKnnAddSampleClassKnnAddSampleClassKnn. The added data affects the classification only, if train_class_knntrain_class_knnTrainClassKnnTrainClassKnnTrainClassKnn is called again.

Automatic feature normalization can be activated by setting 'normalization'"normalization""normalization""normalization""normalization" in GenParamNameGenParamNameGenParamNameGenParamNamegenParamName and 'true'"true""true""true""true" in GenParamValueGenParamValueGenParamValueGenParamValuegenParamValue. The feature vectors are normalized by normalizing each dimension seperately. For each dimension, the mean and standard deviation is calculated over the training samples. Every feature vector is normalized by subtracting the mean and dividing by the standard deviation of the individual dimension. This results in a normalization, where each dimension has zero mean and unit variance. If the standard deviation happens to be zero, only the mean is subtracted. Please note however, that a feature dimension with no standard deviation does not change the classification result and should be removed. Automatic feature normalization will change the stored training data, but the original data can be restored at any time by calling train_class_knntrain_class_knnTrainClassKnnTrainClassKnnTrainClassKnn with 'normalization'"normalization""normalization""normalization""normalization" set to 'false'"false""false""false""false". If normalization is used, the operator classify_class_knnclassify_class_knnClassifyClassKnnClassifyClassKnnClassifyClassKnn interprets the input data as unnormalized and performs normalization internally as it has been defined in the last call to train_class_knntrain_class_knnTrainClassKnnTrainClassKnnTrainClassKnn.

Execution Information

This operator modifies the state of the following input parameter:

The value of this parameter may not be shared across multiple threads without external synchronization.


KNNHandleKNNHandleKNNHandleKNNHandleKNNHandle (input_control, state is modified)  class_knn HClassKnn, HTupleHTupleHtuple (integer) (IntPtr) (Hlong) (Hlong)

Handle of the k-NN classifier.

GenParamNameGenParamNameGenParamNameGenParamNamegenParamName (input_control)  string-array HTupleHTupleHtuple (string) (string) (HString) (char*)

Names of the generic parameters that can be adjusted for the k-NN classifier creation.

Default value: []

List of values: 'normalization'"normalization""normalization""normalization""normalization", 'num_trees'"num_trees""num_trees""num_trees""num_trees"

GenParamValueGenParamValueGenParamValueGenParamValuegenParamValue (input_control)  number-array HTupleHTupleHtuple (integer / string / real) (int / long / string / double) (Hlong / HString / double) (Hlong / char* / double)

Values of the generic parameters that can be adjusted for the k-NN classifier creation.

Default value: []

Suggested values: 4, 'false'"false""false""false""false", 'true'"true""true""true""true"


If the parameters are valid, the operator train_class_knntrain_class_knnTrainClassKnnTrainClassKnnTrainClassKnn returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Possible Predecessors

add_sample_class_knnadd_sample_class_knnAddSampleClassKnnAddSampleClassKnnAddSampleClassKnn, read_class_knnread_class_knnReadClassKnnReadClassKnnReadClassKnn



See also

create_class_knncreate_class_knnCreateClassKnnCreateClassKnnCreateClassKnn, read_class_knnread_class_knnReadClassKnnReadClassKnnReadClassKnn


Marius Muja, David G. Lowe: “Fast Approximate Nearest Neighbors with Automatic Algorithm Configuration”; International Conference on Computer Vision Theory and Applications (VISAPP 09); 2009.



ClassesClasses | | Operators