mlnext.anomaly.find_anomalies#

mlnext.anomaly.find_anomalies(y: ndarray | DataFrame) List[Tuple[int, int]][source]#

Finds continuous segments of anomalies and returns a list of tuple with the start end end index of each anomaly.

Parameters:

y (T.union[np.ndarray, pd.DataFrame]) – Array of labels (1d).

Returns:

Returns a list of tuples. A tuple consists of 2 elements with the start and end index of the anomaly.

Return type:

T.List[T.Tuple[int, int]]

Example

>>> find_anomalies(np.array([0, 1, 1, 0, 1, 0, 1, 1]))
[(1, 2), (4, 4), (6, 7)]