StreamAD Utilities#

Dataset#

UnivariateDS#

class streamad.util.UnivariateDS[source]#

Bases: streamad.util.dataset.DS

Load univariate dataset.


MultivariateDS#

class streamad.util.MultivariateDS(has_names=False)[source]#

Bases: streamad.util.dataset.DS

Load multivariate dataset.


CustomDS#

class streamad.util.CustomDS(f_path, label=None)[source]#

Bases: streamad.util.dataset.DS

Load custom dataset. :type f_path: Union[str, ndarray] :param f_path: Dataset or its path. :type f_path: Union[str, np.ndarray] :type label: Optional[ndarray] :param label: Anomaly labels for dataset. Defaults to None. :type label: np.ndarray, optional


Generator#

StreamGenerator#

class streamad.util.StreamGenerator(X)[source]#

Bases: object

Load static dataset and generate observation once a time.

Parameters

X (np.ndarray) – Origin static dataset.

Raises

TypeError – Unexpected input data type.

iter_item()[source]#

Iterate item once a time from the dataset.

Yields

Generator – One observation from the dataset.

Return type

Generator


Math toolkit#

Statistic#

class streamad.util.StreamStatistic(is_global=True, window_len=10)[source]#

Bases: object

Data statistics for the streaming data, with supporting max, min, sum, mean, sum of squares, var, std and standard scaler.

__init__(is_global=True, window_len=10)[source]#

Statistics for the streaming data, with supporting max, min, sum, mean, sum of squares, var, std and standard scaler.

Parameters
  • is_global (bool, optional) – For whole stream or a windowed stream. Defaults to True.

  • window_len (int, optional) – Rolloing window length. Only works when is_global is False. Defaults to 10.

get_max()[source]#

Get max statistic.

get_mean()[source]#

Get mean statistic.

get_min()[source]#

Get min statistic.

get_std()[source]#

Get max statistic.

get_sum()[source]#

Get sum statistic.

get_var()[source]#

Get var statistic.

update(X)[source]#

Update a pd.Series to stream

Parameters

X (np.ndarray) – An item from StreamGenerator


Visualization#

Plot#

class streamad.util.plot(data, scores, date=None, features=None, label=None)[source]#

Bases:

Plot data, score and ground truth (if exists).

Parameters
  • data (np.array) – Original data stream.

  • scores (np.array) – Anomaly scores of the data stream.

  • date (np.array, optional) – Timestamp of the data. Defaults to None.

  • features (np.array, optional) – Features name. Defaults to None.

  • label (np.array, optional) – Ground truth. Defaults to None.