kats.detectors.hourly_ratio_detection module¶
- class kats.detectors.hourly_ratio_detection.HourlyRatioDetector(data: kats.consts.TimeSeriesData, freq: Optional[Union[str, pandas._libs.tslibs.timedeltas.Timedelta]] = None, aggregate: Optional[str] = None)[source]¶
Bases:
kats.detectors.detector.Detector
Hourly Ratio Anormaly detector.
This detector detects the abnormal intra-day hourly ratio patterns. This detector takes TimeSeriesDataas input and returns a list of TimeSeriesChangePoint representing the abnormal dates. The detection algorithm assumes that the hourly ratio of each day should follow a multivariate normal distribution, and we utilize Mahalanobis distance tests to detect abnormal days. This class provides detector and plot.
- data¶
A
kats.consts.TimeSeriesData
object representing the data to be examed, which should be of hour-level granularity.
- freq¶
Optional; A string or a pandas.Timedelta object representing the data frequency (following the naming conventions of pandas). Can be ‘H’ (hourly frequency), ‘T’ minutely frequency, ‘S’ secondly frequency or any other frequency finer than hourly frequency. Default is None, in which case the frequency will be infered by infer_freq_robust.
- aggregate¶
Optional; A string representing the aggregation method for aggregating data to hourly level data. Can be ‘min’, ‘max’, ‘sum’, ‘mean’ or None. Default is None, which means no aggregation.
- Sample Usage:
>>> hr = HourlyRatioDetector(data) >>> anomlies=hr.detector() >>> hr = hr.plot(weekday = 3) # Plot the anomalies of weekday 3
- detector(support_fraction=0.9) → List[kats.consts.TimeSeriesChangePoint][source]¶
Run detection algorithm.
- Parameters
support_fraction – Optional; A float representing the support_fraction for MinCovDet class from scikit-learn. Default is 0.9. See https://scikit-learn.org/stable/modules/generated/sklearn.covariance.MinCovDet.html for more details.
- Returns
A list of TimeSeriesChangePoint representing the anormal dates.