kats.detectors.prophet_detector module¶

This module contains code to implement the Prophet algorithm as a Detector Model.

class kats.detectors.prophet_detector.ProphetDetectorModel(strictness_factor: float = 0.8, uncertainty_samples: float = 50, serialized_model: Optional[bytes] = None, remove_outliers=False, score_func: kats.detectors.prophet_detector.ProphetScoreFunction = 'deviation_from_predicted_val')[source]¶

Bases: kats.detectors.detector.DetectorModel

Prophet based anomaly detection model.

A Detector Model that does anomaly detection, buy first using the Prophet library to forecast the interval for the next point, and comparing this to the actually observed data point.

strictness_factor¶

interval_width as required by Prophet.

uncertainty_samples¶

Number of samples required by Prophet to calculate uncertainty.

serialized_model¶

json, representing data from a previously serialized model.

fit(data: kats.consts.TimeSeriesData, historical_data: Optional[kats.consts.TimeSeriesData] = None)None[source]¶

Used to train a model.

fit can be called during priming. We train a model using all the data passed in.

Parameters
  • data – TimeSeriesData on which detection is run.

  • historical_data – TimeSeriesData corresponding to history. History ends exactly where the data begins.

Returns

None.

fit_predict(data: kats.consts.TimeSeriesData, historical_data: Optional[kats.consts.TimeSeriesData] = None)kats.detectors.detector_consts.AnomalyResponse[source]¶

Trains a model, and returns the anomaly scores.

Returns the AnomalyResponse, when data is passed to it.

Parameters
  • data – TimeSeriesData on which detection is run.

  • historical_data – TimeSeriesData corresponding to history. History ends exactly where the data begins.

Returns

AnomalyResponse object. The length of this object is same as data. The score property gives the score for anomaly.

predict(data: kats.consts.TimeSeriesData, historical_data: Optional[kats.consts.TimeSeriesData] = None)kats.detectors.detector_consts.AnomalyResponse[source]¶

Predicts anomaly score for future data.

Predict only expects anomaly score for data. Prophet doesn’t need historical_data.

Parameters
  • data – TimeSeriesData on which detection is run

  • historical_data – TimeSeriesData corresponding to history. History ends exactly where the data begins.

Returns

AnomalyResponse object. The length of this obj.ect is same as data. The score property gives the score for anomaly.

serialize()bytes[source]¶

Serialize the model into a json.

So it can be loaded later.

Returns

json containing information of the model.

class kats.detectors.prophet_detector.ProphetScoreFunction(value)[source]¶

Bases: enum.Enum

An enumeration.

kats.detectors.prophet_detector.timeseries_to_prophet_df(ts_data: kats.consts.TimeSeriesData)pandas.core.frame.DataFrame[source]¶

Converts a object of TimeSeriesData to a dataframe, as expected by Prophet.

Parameters

ts_data – object of class TimeSeriesData.

Returns

pandas DataFrame expected by Prophet.