filter_by_label

ketos.neural_networks.dev_utils.detection.filter_by_label(detecitons, labels)[source]

Filters the input DataFrame by specified label(s).

Args:
detections: pandas DataFrame

A DataFrame containing the results data.

labels: list or integer

A list of labels to filter by.

Returns:
pandas.DataFrame:

A DataFrame containing only the detections with the specified labels.

Example:

>>> import pandas as pd
>>> df = pd.DataFrame({
...     'filename': ['file1.wav', 'file2.wav', 'file3.wav'],
...     'start': [0.0, 20.0, 40.0],
...     'end': [20.0, 40.0, 60.0],
...     'label': [0, 1, 2],
...     'score': [0.6, 0.8, 0.7]
... })
>>> filtered_df = filter_by_label(df, 1)
>>> filtered_df = filtered_df.reset_index(drop=True)
>>> filtered_df.equals(pd.DataFrame({
...     'filename': ['file2.wav'],
...     'start': [20.0],
...     'end': [40.0],
...     'label': [1],
...     'score': [0.8]
... }))
True