Skip to content

train_class_knnTrainClassKnnTrainClassKnntrain_class_knnT_train_class_knnπŸ”—

Short descriptionπŸ”—

train_class_knnTrainClassKnnTrainClassKnntrain_class_knnT_train_class_knn β€” Creates the search trees for a k-NN classifier.

SignatureπŸ”—

train_class_knn( class_knn KNNHandle, string GenParamName, number GenParamValue )void TrainClassKnn( const HTuple& KNNHandle, const HTuple& GenParamName, const HTuple& GenParamValue )static void HOperatorSet.TrainClassKnn( HTuple KNNHandle, HTuple genParamName, HTuple genParamValue )def train_class_knn( knnhandle: HHandle, gen_param_name: Sequence[str], gen_param_value: Sequence[Union[int, str, float]] ) -> None

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

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

void HClassKnn.TrainClassKnn( HTuple genParamName, HTuple genParamValue )

DescriptionπŸ”—

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

It is possible to set the number of trees via the parameters GenParamNamegenParamNamegen_param_name and GenParamValuegenParamValuegen_param_value by 'num_trees'"num_trees". The default value for the number of search trees is 44. 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_knnAddSampleClassKnn. The added data affects the classification only, if train_class_knnTrainClassKnn is called again.

Automatic feature normalization can be activated by setting 'normalization'"normalization" in GenParamNamegenParamNamegen_param_name and 'true'"true" in GenParamValuegenParamValuegen_param_value. The feature vectors are normalized by normalizing each dimension separately. 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_knnTrainClassKnn with 'normalization'"normalization" set to 'false'"false". If normalization is used, the operator classify_class_knnClassifyClassKnn interprets the input data as unnormalized and performs normalization internally as it has been defined in the last call to train_class_knnTrainClassKnn.

Execution informationπŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

This operator modifies the state of the following input parameter:

During execution of this operator, access to the value of this parameter must be synchronized if it is used across multiple threads.

ParametersπŸ”—

KNNHandleKNNHandleknnhandle (input_control, state is modified) class_knn β†’ (handle)HTuple (HHandle)HClassKnn, HTuple (IntPtr)HHandleHtuple (handle)

Handle of the k-NN classifier.

GenParamNamegenParamNamegen_param_name (input_control) string-array β†’ (string)HTuple (HString)HTuple (string)Sequence[str]Htuple (char*)

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

Default: [][]
List of values: 'normalization', 'num_trees'"normalization", "num_trees"

GenParamValuegenParamValuegen_param_value (input_control) number-array β†’ (integer / string / real)HTuple (Hlong / HString / double)HTuple (int / long / string / double)Sequence[Union[int, str, float]]Htuple (Hlong / char* / double)

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

Default: [][]
Suggested values: 4, 'false', 'true'4, "false", "true"

ResultπŸ”—

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

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

add_sample_class_knnAddSampleClassKnn, read_class_knnReadClassKnn

Alternatives

select_feature_set_knnSelectFeatureSetKnn

See also

create_class_knnCreateClassKnn, read_class_knnReadClassKnn

ReferencesπŸ”—

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

ModuleπŸ”—

Foundation