results

class BaseResult

Bases: object

Base class for classification results.

f1_score(on)

Calculate the F1 score for the given data.

Parameters:

on (Literal['timestamp', 'annotation', 'prediction']) –

The level on which to calculate the F1 scores.

  • "timestamp": Calculate the F1 scores across all samples (timestamps).

  • "annotation": Calculate the F1 scores based on the annotated intervals.

  • "prediction": Calculate the F1 scores based on the predicted intervals.

Return type:

Series

remove_overlapping_predictions(*, priority_function, prefilter_recipient_bouts, max_bout_gap, max_allowed_bout_overlap)

Remove overlapping predictions from the classification result.

This method is implemented by subclasses if applicable.

Parameters:
  • priority_function (Callable[[DataFrame], Iterable[float]]) – A function that assigns a priority to each prediction.

  • prefilter_recipient_bouts (bool) – Whether to prefilter recipient bouts.

  • max_bout_gap (float) – The maximum allowed gap between predictions.

  • max_allowed_bout_overlap (float) – The maximum allowed overlap between predictions.

Return type:

Self

score()

Return a summary of the F1 scores for each category at different levels.

Return type:

DataFrame

Returns:

A DataFrame containing the F1 scores for each category at different levels.

See also

f1_score()

class ClassificationResult(categories, timestamps, y_proba, y_pred_numeric, _y_proba_smoothed=None, _predictions=None, _annotations=None, _y_true_numeric=None)

Bases: BaseResult

Parameters:
property annotations: DataFrame

Annotated intervals.

Raises:

ValueError – If the result is not annotated.

categories: tuple[str, ...]
classmethod from_h5(data_file, data_path)

Load classification results from an HDF5 file.

Parameters:
  • data_file (str) – Path to the HDF5 file.

  • data_path (str) – Path within the HDF5 file to load the data.

Return type:

ClassificationResult

property predictions: DataFrame

Predicted intervals.

Raises:

ValueError – If the result is not thresholded.

smooth(smoothing_func, *, threshold=True, decision_thresholds=None, default_decision='none')

Apply smoothing functions to the classification result.

Parameters:
  • smoothing_func (SmoothingFunction) – The smoothing function to apply.

  • threshold (bool, default: True) – Whether to threshold the result.

  • decision_thresholds (Iterable[float] | None, default: None) – The decision thresholds to use.

  • default_decision (int | str, default: 'none') – The default decision to use.

Return type:

ClassificationResult

Returns:

The smoothed classification result.

threshold(decision_thresholds=None, *, default_decision='none')

Apply decision thresholds to the classification result.

Parameters:
  • decision_thresholds (Iterable[float] | None, default: None) – A list of decision thresholds for each category.

  • default_decision (int | str, default: 'none') – The default decision to apply if no category surpasses the threshold.

Return type:

ClassificationResult

timestamps: ndarray
to_h5(data_file, data_path)

Save the classification results to an HDF5 file.

Parameters:
  • data_file (str) – Path to the HDF5 file.

  • data_path (str) – Path within the HDF5 file to save the data.

y_pred_numeric: ndarray
y_proba: ndarray
property y_proba_smoothed

Smoothed classification probabilities.

property y_true_numeric

True labels, represented as integers.

Raises:

ValueError – If the result is not annotated.

class DatasetClassificationResult(classification_results, target)

Bases: _NestedResult

Parameters:
property annotations: DataFrame

Concatenated annotations of all groups.

classification_results: dict[str | int, GroupClassificationResult]
classmethod combine(results)

Combine multiple dataset classification results into a single result.

Parameters:

results (Iterable[DatasetClassificationResult]) – The dataset classification results to combine.

Return type:

DatasetClassificationResult

Returns:

A new DatasetClassificationResult with the combined results.

classmethod from_h5(data_file, *, dataset_name)

Load the dataset classification result from an HDF5 file.

Parameters:
  • data_file (str) – The path to the HDF5 file.

  • dataset_name (str) – The name of the dataset within the HDF5 file.

Return type:

DatasetClassificationResult

Returns:

The loaded dataset classification result.

property predictions: DataFrame

Concatenated predictions of all groups.

to_dataset(*, trajectories, background_category)

Convert the classification results to an annotated dataset.

Parameters:
  • trajectories (Mapping[str | int, Mapping[str | int, Trajectory]]) – Mapping from group identifier to mapping from individual identifier to trajectory.

  • background_category (str) – Category to use as background category.

Return type:

AnnotatedDataset

Returns:

Annotated dataset.

to_h5(data_file, *, dataset_name)

Save the dataset classification result to an HDF5 file.

Parameters:
  • data_file (str) – The path to the HDF5 file.

  • dataset_name (str) – The name of the dataset within the HDF5 file.

class GroupClassificationResult(classification_results, target, individuals)

Bases: _NestedResult

Parameters:
property annotations: DataFrame

Concatenated annotations of all classification results.

classification_results: dict[str | int | tuple[str | int, str | int], ClassificationResult]
classmethod combine(results)

Combine multiple GroupClassificationResult into a single one.

Parameters:

results (Iterable[GroupClassificationResult]) – Iterable of GroupClassificationResult to combine.

Return type:

GroupClassificationResult

Returns:

A new GroupClassificationResult object containing the combined results.

classmethod from_h5(data_file, data_path)

Load a GroupClassificationResult from a HDF5 file.

Parameters:
  • data_file (str) – The path to the HDF5 file.

  • data_path (str) – The path to the data within the HDF5 file.

Return type:

GroupClassificationResult

Returns:

The loaded group classification result.

individuals: tuple[str | int, ...]
property predictions: DataFrame

Concatenated predictions of all classification results.

to_h5(data_file, data_path)

Save the GroupClassificationResult to an HDF5 file.

Parameters:
  • data_file (str) – Path to the HDF5 file.

  • data_path (str) – Path within the HDF5 file to save the data.