zoo.zouwu.model package

Submodules

zoo.zouwu.model.anomaly module

class zoo.zouwu.model.anomaly.DetectorBase[source]

Bases: object

Base class for detector

detect(y, **kwargs)[source]

Detect anomalies in dataset :param y: the dataset :return: the anomaly indexes in y

class zoo.zouwu.model.anomaly.Distance[source]

Bases: object

The Base Distance Class.

distance(x, y)[source]

Calculate the distance between x and y. a and b should be in same shape. :param x: the first tensor :param y: the second tensor :return: the absolute distance between x and y

class zoo.zouwu.model.anomaly.EuclideanDistance[source]

Bases: zoo.zouwu.model.anomaly.Distance

Euclidean Distance Measure

distance(x, y)[source]

Calculate the distance between x and y. a and b should be in same shape. :param x: the first tensor :param y: the second tensor :return: the absolute distance between x and y

class zoo.zouwu.model.anomaly.ThresholdDetector[source]

Bases: zoo.zouwu.model.anomaly.DetectorBase

Anomaly detector

detect(y, yhat=None, threshold=inf, dist_measure=<zoo.zouwu.model.anomaly.EuclideanDistance object>)[source]

Detect anomalies. Each sample can have 1 or more dimensions. :param dist_measure: :param y: the values to detect. shape could be

1-D (num_samples,) or 2-D array (num_samples, features)
Parameters:
  • yhat – the estimated values, a tensor with same shape as y, could be None when threshold is a tuple
  • threshold – threshold, could be 1. a single value - absolute distance threshold, same for all samples 2. a 1-D array in shape (num_samples,) - per sample absolute distance threshold 3. a tensor in same shape as y and yhat - per dimension absolute distance threshold 4. a tuple (min, max) min and max tensors, same shape as y, yhat is ignored in this case
Returns:

the anomaly values indexes in the samples, i.e. num_samples dimension.

class zoo.zouwu.model.anomaly.ThresholdEstimator[source]

Bases: object

An estimator to find the proper threshold.

fit(y, yhat, mode='default', ratio=0.01, dist_measure=<zoo.zouwu.model.anomaly.EuclideanDistance object>)[source]

fit the y and yhat and find the proper threshold :param y: actual values :param yhat: predicted values :param mode: types of ways to find threshold

“default” : fit data to a uniform distribution (the percentile way) “gaussian”: fit data to a gaussian distribution *TBD
Parameters:ratio – the ratio of anomaly to consider as anomaly.
Returns:the threshold

zoo.zouwu.model.forecast module

Module contents