Обнаружение выбросов в табличных данных¶
Детектор для обнаружения аномалий в данных без учителя. Этот модуль состоит из детекторов, которые управляют объектами scores, поскольку в этом методе каждая строка имеет свою собственную оценку аномальности.
Подробнее читайте в Руководстве пользователя.
Детектор¶
A tabular detector for anomaly detection.
This class provides methods for fitting a pipeline, scoring data, and predicting anomalies in tabular datasets. It supports multiple scoring methods, including mixed, proximity-based, and model-based scoring.
Source code in applybn/anomaly_detection/static_anomaly_detector/tabular_detector.py
23 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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
__getattr__(attr)
¶
Delegates attribute access to the pipeline if the attribute is not found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr
|
str
|
The name of the attribute. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
The value of the attribute. |
Raises:
Type | Description |
---|---|
NotFittedError
|
If the pipeline is not fitted. |
Source code in applybn/anomaly_detection/static_anomaly_detector/tabular_detector.py
__init__(target_name=None, score='mixed', additional_score='LOF', thresholding_strategy='best_from_range', model_estimation_method=None, verbose=1)
¶
Initializes the TabularDetector object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_name
|
None | str
|
The name of the target column in the dataset. |
None
|
score
|
Literal['mixed', 'proximity', 'model']
|
The scoring method to use ("mixed", "proximity", or "model"). |
'mixed'
|
additional_score
|
None | str
|
The additional proximity-based scoring method (e.g., "LOF"). |
'LOF'
|
thresholding_strategy
|
None | str
|
The strategy for thresholding scores (e.g., "best_from_range"). |
'best_from_range'
|
model_estimation_method
|
None | str | dict[Literal['cont', 'disc'], Literal['original_modified', 'iqr', 'cond_ratio']]
|
The method for model-based scoring, specified separately for continuous and discrete variables. |
None
|
verbose
|
int
|
The verbosity level for logging. Default is 1. |
1
|
Source code in applybn/anomaly_detection/static_anomaly_detector/tabular_detector.py
construct_score(**scorer_args)
¶
Constructs a scoring object based on the selected scoring method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**scorer_args
|
Additional arguments for the scoring object. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Score |
The constructed scoring object. |
Source code in applybn/anomaly_detection/static_anomaly_detector/tabular_detector.py
decision_function(X)
¶
Computes the anomaly scores for the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
The input data. |
required |
Returns:
Type | Description |
---|---|
np.ndarray: The computed anomaly scores. |
Source code in applybn/anomaly_detection/static_anomaly_detector/tabular_detector.py
fit(X, y=None)
¶
Fits the anomaly detection pipeline to the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
The input data. |
required |
y
|
The target values. Not used. |
None
|
Returns:
Name | Type | Description |
---|---|---|
TabularDetector |
The fitted detector. |
Raises:
Type | Description |
---|---|
KeyError
|
If the target column is not found in the input data. |
Source code in applybn/anomaly_detection/static_anomaly_detector/tabular_detector.py
plot_result(predicted)
¶
Plots the results of the anomaly detection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predicted
|
ndarray | Series
|
The predicted labels. |
required |
Source code in applybn/anomaly_detection/static_anomaly_detector/tabular_detector.py
predict(X)
¶
Predicts whether each data point is an anomaly or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
The input data. |
required |
Returns:
Type | Description |
---|---|
np.ndarray: An array of binary predictions (1 for anomaly, 0 for normal). |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If unsupervised thresholding is not implemented. |
Source code in applybn/anomaly_detection/static_anomaly_detector/tabular_detector.py
predict_scores(X)
¶
Predicts the anomaly scores for the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
The input data. |
required |
Returns:
Type | Description |
---|---|
np.ndarray: The predicted anomaly scores. |
Source code in applybn/anomaly_detection/static_anomaly_detector/tabular_detector.py
threshold_search_supervised(y, y_pred)
staticmethod
¶
Searches for the best threshold to maximize the F1 score.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
The true labels. |
required | |
y_pred
|
ndarray
|
The predicted scores. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The best threshold. |