pusion.core.k_nearest_neighbors_combiner.py¶
- class pusion.core.k_nearest_neighbors_combiner.KNNCombiner¶
Bases:
pusion.core.combiner.TrainableCombiner
The
KNNCombiner
(kNN) is a learning and classifier-based combiner that converts multiple decision outputs into new features, which in turn are used to train this combiner. The kNN combiner (k=5) uses uniform weights for all neighbors and the standard Euclidean metric for the distance.- train(decision_tensor, true_assignments)¶
Train the kNN combiner by fitting the k nearest neighbors (k=5) model with given decision outputs and true class assignments. Both continuous and crisp classification outputs are supported. This procedure transforms decision outputs into a new feature space.
- Parameters
decision_tensor – numpy.array of shape (n_classifiers, n_samples, n_classes). Tensor of either crisp or continuous decision outputs by different classifiers per sample.
true_assignments – numpy.array of shape (n_samples, n_classes). Matrix of either crisp or continuous class assignments which are considered true for each sample during the training procedure.
- combine(decision_tensor)¶
Combine decision outputs by the k nearest neighbors (k=5) model. Both continuous and crisp classification outputs are supported. Combining requires a trained
DecisionTreeCombiner
. This procedure transforms decision outputs into a new feature space.- Parameters
decision_tensor – numpy.array of shape (n_classifiers, n_samples, n_classes). Tensor of either crisp or continuous decision outputs by different classifiers per sample.
- Returns
A matrix (numpy.array) of either crisp or continuous class assignments which represents fused decisions obtained by kNN. Axis 0 represents samples and axis 1 the class assignments which are aligned with axis 2 in
decision_tensor
input tensor.
- class pusion.core.k_nearest_neighbors_combiner.CRKNNCombiner¶
Bases:
pusion.core.k_nearest_neighbors_combiner.KNNCombiner
The
CRKNNCombiner
is a modification ofKNNCombiner
that also supports complementary-redundant decision outputs. Therefore the input is transformed, such that all missing classification assignments are considered as a constant, respectively. To use methodstrain()
andcombine()
a coverage needs to be set first by the inheritedset_coverage()
method.- train(decision_outputs, true_assignments)¶
Train the kNN combiner model by fitting the k nearest neighbors (k=5) model with given decision outputs and true class assignments. Both continuous and crisp classification outputs are supported. This procedure transforms decision outputs into a new feature space.
- Parameters
decision_outputs – list of numpy.array matrices, each of shape (n_samples, n_classes’), where n_classes’ is classifier-specific and described by the coverage. Each matrix corresponds to one of n_classifiers classifiers and contains either crisp or continuous decision outputs per sample.
true_assignments – numpy.array of shape (n_samples, n_classes). Matrix of either crisp or continuous class assignments which are considered true for each sample during the training procedure.
- combine(decision_outputs)¶
Combine decision outputs by the k nearest neighbors (k=5) model. Both continuous and crisp classification outputs are supported. Combining requires a trained
DecisionTreeCombiner
. This procedure transforms decision outputs into a new feature space.- Parameters
decision_outputs – list of numpy.array matrices, each of shape (n_samples, n_classes’), where n_classes’ is classifier-specific and described by the coverage. Each matrix corresponds to one of n_classifiers classifiers and contains crisp or continuous decision outputs per sample.
- Returns
A matrix (numpy.array) of crisp or continuous class assignments which represents fused decisions. Axis 0 represents samples and axis 1 the class labels which are aligned with axis 2 in
decision_tensor
input tensor.