Обнаружение выбросов во временных рядах¶
FastTimeSeriesDetector для обнаружения аномалий во временных рядах без учителя на основе реализации на Java. Для интеграции этого модуля была внесена необходимая модификация.
Подробнее читайте в Руководстве пользователя.
Детектор¶
A time-series anomaly detection model based on Dynamic Bayesian Network (DBN) structure learning implemented in Java and accessed via JPype.
This class supports both pre-sliced DBN data and automatic transformation of raw tabular time-series data using a sliding window mechanism.
Source code in applybn/anomaly_detection/dynamic_anomaly_detector/fast_time_series_detector.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
__init__(abs_threshold=-4.5, rel_threshold=0.8, num_parents=3, artificial_slicing=False, artificial_slicing_params=None, scoring_function='ll', markov_lag=1, non_stationary=False)
¶
Initializes the FastTimeSeriesDetector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
abs_threshold
|
float
|
Absolute score below which values are flagged as anomalies. |
-4.5
|
rel_threshold
|
float
|
Fraction of features with anomaly scores needed to flag the full sample. |
0.8
|
num_parents
|
int
|
Maximum number of parents allowed in the DBN structure. |
3
|
artificial_slicing
|
bool
|
Whether to apply window-based transformation on the input data. |
False
|
artificial_slicing_params
|
dict
|
Parameters for the TemporalDBNTransformer (e.g., window size). |
None
|
scoring_function
|
str
|
Scoring function used by the Java DBN learner ('ll' or 'MDL'). |
'll'
|
markov_lag
|
int
|
The Markov lag (time distance) for DBN learning. |
1
|
non_stationary
|
bool
|
Learn separate models for each transition instead of one shared model. |
False
|
Source code in applybn/anomaly_detection/dynamic_anomaly_detector/fast_time_series_detector.py
calibrate(y_true, calibration_bounds=None, verbose=1, calibration_params=None)
¶
A method to calibrate the DBN. Calibration means finding absolute and relative thresholds. Utilizes bayesian optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_true
|
Series | ndarray
|
values to calibrate on |
required |
calibration_bounds
|
dict | None
|
bound of calibration values. Must contain abs_thrs and rel_thrs keys. |
None
|
verbose
|
int
|
verbosity level. |
1
|
calibration_params
|
dict
|
calibration parameters for optimization. |
None
|
Source code in applybn/anomaly_detection/dynamic_anomaly_detector/fast_time_series_detector.py
decision_function(X)
¶
Calls the Java backend to score transitions using DBN inference.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
Preprocessed DBN-compatible DataFrame. |
required |
Returns:
Type | Description |
---|---|
np.ndarray: 2D array of log-likelihood scores from the Java model. |
Source code in applybn/anomaly_detection/dynamic_anomaly_detector/fast_time_series_detector.py
fit(X)
¶
Trains the DBN model using input data. If artificial slicing is enabled, performs time-window transformation before training.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
Input data (time-series features). |
required |
Returns:
Type | Description |
---|---|
np.ndarray: Anomaly labels (0 for normal, 1 for anomalous). |
Source code in applybn/anomaly_detection/dynamic_anomaly_detector/fast_time_series_detector.py
predict(X=None)
¶
Trains the model and applies anomaly decision logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
Input features. Not used. |
None
|
Returns:
Type | Description |
---|---|
np.ndarray: Binary anomaly labels (1 = anomalous). |
Source code in applybn/anomaly_detection/dynamic_anomaly_detector/fast_time_series_detector.py
predict_scores(X=None)
¶
Computes raw anomaly scores from the trained DBN.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
Input data. Not used in this implementation. |
None
|
Returns:
Type | Description |
---|---|
np.ndarray: Raw scores. |