Skip to content

classify_class_knnClassifyClassKnnClassifyClassKnnclassify_class_knnT_classify_class_knnπŸ”—

Short descriptionπŸ”—

classify_class_knnClassifyClassKnnClassifyClassKnnclassify_class_knnT_classify_class_knn β€” Search for the next neighbors for a given feature vector.

SignatureπŸ”—

classify_class_knn( class_knn KNNHandle, number Features, out number Result, out number Rating )void ClassifyClassKnn( const HTuple& KNNHandle, const HTuple& Features, HTuple* Result, HTuple* Rating )static void HOperatorSet.ClassifyClassKnn( HTuple KNNHandle, HTuple features, out HTuple result, out HTuple rating )def classify_class_knn( knnhandle: HHandle, features: Sequence[float] ) -> Tuple[Sequence[int], Sequence[float]]

Herror T_classify_class_knn( const Htuple KNNHandle, const Htuple Features, Htuple* Result, Htuple* Rating )

HTuple HClassKnn::ClassifyClassKnn( const HTuple& Features, HTuple* Rating ) const

HTuple HClassKnn.ClassifyClassKnn( HTuple features, out HTuple rating )

DescriptionπŸ”—

classify_class_knnClassifyClassKnn searches for the next 'k'"k" neighbors of the feature vector given in Featuresfeaturesfeatures. The distance which is used to determine the next neighbor is the L2-norm of the given vector and the training samples.

The value of 'k'"k" can be set via set_params_class_knnSetParamsClassKnn. The results can either be the determined class of the feature vector or the indices of the nearest neighbors. The selection of the result behavior can be made by set_params_class_knnSetParamsClassKnn via the generic parameters 'method'"method" and 'max_num_classes'"max_num_classes":

  • 'classes_distance'"classes_distance": returns the nearest samples for each of maximally 'max_num_classes'"max_num_classes" different classes, if they have a representative in the nearest 'k'"k" neighbors. The results in Resultresultresult are classes sorted by their minimal distance in Ratingratingrating. There is no efficient way to determine in a k-NN-tree the nearest neighbor for exactly 'max_num_classes'"max_num_classes" classes.

  • 'classes_frequency'"classes_frequency": counts the occurrences of certain classes among the nearest 'k'"k" neighbors and returns the occurring classes in Resultresultresult sorted by their relative frequency that is returned in Ratingratingrating. Again, maximally 'max_num_classes'"max_num_classes" values are returned.

  • 'classes_weighted_frequencies'"classes_weighted_frequencies": counts the occurrences of certain classes among the nearest 'k'"k" neighbors and returns the occurring classes in Resultresultresult sorted by their relative frequency weighted with the average distance that is returned in Ratingratingrating. Again, maximally 'max_num_classes'"max_num_classes" values are returned.

  • 'neighbors_distance'"neighbors_distance": returns the indices of the nearest 'k'"k" neighbors in Resultresultresult and the distances in Ratingratingrating.

The default behavior is 'classes_distance'"classes_distance" and returns the classes and distances.

Execution informationπŸ”—

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

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

  • Automatically parallelized on internal data level.

ParametersπŸ”—

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

Handle of the k-NN classifier.

Featuresfeaturesfeatures (input_control) number-array β†’ (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Features that should be classified.

Resultresultresult (output_control) number-array β†’ (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

The classification result, either class IDs or sample indices.

Ratingratingrating (output_control) number-array β†’ (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

A rating for the results. This value contains either a distance, a frequency or a weighted frequency.

ResultπŸ”—

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

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

train_class_knnTrainClassKnn, read_class_knnReadClassKnn, set_params_class_knnSetParamsClassKnn

Possible successors

clear_class_knnClearClassKnn

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