Skip to main content
Version: 0.5.x

multiclass

Utility functions for handling classes with multiple categories.

Module: aisp.utils.multiclass
Import: from aisp.utils import multiclass

Functions

slice_index_list_by_class

def slice_index_list_by_class(classes: Optional[Union[npt.NDArray, list]], y: npt.NDArray) -> dict:
...

Separate indices of samples by class for targeted iteration.

Parameters

NameTypeDefaultDescription
classesOptional[Union[npt.NDArray, list]]-list with unique classes.
ynpt.NDArray-Receives a y (n_samples) array with the output classes of the X sample array.

Returns

TypeDescription
dictA dictionary with the list of array positions(y), with the classes as key.

Example

import numpy as np
from aisp.utils.multiclass import slice_index_list_by_class

labels = ['a', 'b', 'c']
y = np.array(['a', 'c', 'b', 'a', 'c', 'b'])
slice_index_list_by_class(labels, y)

predict_knn_affinity

def predict_knn_affinity(
X: npt.NDArray,
k: int,
all_cell_vectors: List[Tuple[Union[str, int], npt.NDArray]],
affinity_func: Callable[[npt.NDArray, npt.NDArray], float]
) -> npt.NDArray:
...

Predict classes using k-nearest neighbors and trained cells.

Parameters

NameTypeDefaultDescription
Xnpt.NDArray-Input data to be classified.
kint-Number of nearest neighbors to consider for prediction.
all_cell_vectorsList[Tuple[Union[str, int], npt.NDArray]]-List of tuples (class_name, cell(np.ndarray)).
affinity_funcCallable[[npt.NDArray, npt.NDArray], float]-Function that takes two vectors and returns an affinity value.

Returns

TypeDescription
npt.NDArrayArray of predicted labels for each sample in X, based on the k nearest neighbors.