classify_class_knnT_classify_class_knnClassifyClassKnnClassifyClassKnnclassify_class_knn (Operator)
Name
classify_class_knnT_classify_class_knnClassifyClassKnnClassifyClassKnnclassify_class_knn
— Search for the next neighbors for a given feature vector.
Signature
def classify_class_knn(knnhandle: HHandle, features: Sequence[float]) -> Tuple[Sequence[int], Sequence[float]]
Description
classify_class_knnclassify_class_knnClassifyClassKnnClassifyClassKnnclassify_class_knn
searches for the next 'k'"k""k""k""k"
neighbors of the feature vector given in FeaturesFeaturesFeaturesfeaturesfeatures
.
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""k""k""k" can be set via set_params_class_knnset_params_class_knnSetParamsClassKnnSetParamsClassKnnset_params_class_knn
.
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_knnset_params_class_knnSetParamsClassKnnSetParamsClassKnnset_params_class_knn
via the generic parameters
'method'"method""method""method""method" and 'max_num_classes'"max_num_classes""max_num_classes""max_num_classes""max_num_classes":
- 'classes_distance'"classes_distance""classes_distance""classes_distance""classes_distance":
returns the nearest samples
for each of maximally 'max_num_classes'"max_num_classes""max_num_classes""max_num_classes""max_num_classes" different classes,
if they have a representative in the nearest 'k'"k""k""k""k" neighbors.
The results in ResultResultResultresultresult
are classes sorted by their minimal
distance in RatingRatingRatingratingrating
. There is no efficient way to determine in a
k-NN-tree the nearest neighbor for exactly 'max_num_classes'"max_num_classes""max_num_classes""max_num_classes""max_num_classes"
classes.
- 'classes_frequency'"classes_frequency""classes_frequency""classes_frequency""classes_frequency":
counts the occurrences of certain
classes among the nearest 'k'"k""k""k""k" neighbors and returns the occurring
classes in ResultResultResultresultresult
sorted by their relative frequency that is
returned in RatingRatingRatingratingrating
. Again, maximally 'max_num_classes'"max_num_classes""max_num_classes""max_num_classes""max_num_classes"
values are returned.
- 'classes_weighted_frequencies'"classes_weighted_frequencies""classes_weighted_frequencies""classes_weighted_frequencies""classes_weighted_frequencies":
counts the occurrences of certain classes among the
nearest 'k'"k""k""k""k" neighbors and returns the occurring classes
in ResultResultResultresultresult
sorted by their relative frequency weighted with the
average distance that is returned in RatingRatingRatingratingrating
.
Again, maximally 'max_num_classes'"max_num_classes""max_num_classes""max_num_classes""max_num_classes" values are returned.
- 'neighbors_distance'"neighbors_distance""neighbors_distance""neighbors_distance""neighbors_distance":
returns the indices of the nearest
'k'"k""k""k""k" neighbors in ResultResultResultresultresult
and the distances in RatingRatingRatingratingrating
.
The default behavior is 'classes_distance'"classes_distance""classes_distance""classes_distance""classes_distance" and returns the
classes and distances.
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
KNNHandleKNNHandleKNNHandleKNNHandleknnhandle
(input_control) class_knn →
HClassKnn, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)
Handle of the k-NN classifier.
FeaturesFeaturesFeaturesfeaturesfeatures
(input_control) number-array →
HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)
Features that should be classified.
ResultResultResultresultresult
(output_control) number-array →
HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)
The classification result, either class IDs or sample
indices.
RatingRatingRatingratingrating
(output_control) number-array →
HTupleSequence[float]HTupleHtuple (real) (double) (double) (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_knnclassify_class_knnClassifyClassKnnClassifyClassKnnclassify_class_knn
returns the value 2 (
H_MSG_TRUE)
. If necessary, an exception is raised.
Possible Predecessors
train_class_knntrain_class_knnTrainClassKnnTrainClassKnntrain_class_knn
,
read_class_knnread_class_knnReadClassKnnReadClassKnnread_class_knn
,
set_params_class_knnset_params_class_knnSetParamsClassKnnSetParamsClassKnnset_params_class_knn
Possible Successors
clear_class_knnclear_class_knnClearClassKnnClearClassKnnclear_class_knn
See also
create_class_knncreate_class_knnCreateClassKnnCreateClassKnncreate_class_knn
,
read_class_knnread_class_knnReadClassKnnReadClassKnnread_class_knn
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