RADAR
Subpackages
Submodules
RADAR.base_algorithm_module module
Base Module that performs the main operations needed to adapt every anomaly detection library
- class RADAR.base_algorithm_module.BaseAnomalyDetection(**kwargs)[source]
Bases:
ABCAbstract Base class for every AD library to define the main behaviour of every library and specific algorithm
- decision_scores
The outlier scores of the training data The higher, the more abnormal. Outliers tend to have higher scores. This value is available once the detector is fitted.
- Type:
numpy array of shape (n_samples,)
- label_parser
specific methods or operations to apply to the score values.
- Type:
function of shape (n_samples,) with the
- abstract decision_function(X)[source]
Predict raw anomaly scores of X using the fitted detector.
The anomaly score of an input sample is computed based on the fitted detector. For consistency, outliers are assigned with higher anomaly scores.
- Parameters:
X (numpy array of shape (n_samples, n_features)) – The input samples.
- Returns:
anomaly_scores – The anomaly score of the input samples.
- Return type:
numpy array of shape (n_samples,)
- abstract fit(X, y=None)[source]
Fit detector. y is ignored in unsupervised methods.
- Parameters:
X (numpy array of shape (n_samples, n_features)) – The input samples.
y (Ignored) – Not used, present for API consistency by convention.
- Returns:
self – Fitted estimator.
- Return type:
object
- abstract get_params()[source]
Get parameters for this estimator.
See http://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html and sklearn/base.py for more information.
- Parameters:
deep (bool, optional (default=True)) – If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
params – Parameter names mapped to their values.
- Return type:
mapping of string to any
- abstract predict(X)[source]
Predict if a particular sample is an outlier or not.
- Parameters:
X (numpy array of shape (n_samples, n_features)) – The input samples.
- Returns:
outlier_labels – For each observation, tells whether it should be considered as an outlier according to the fitted model. 0 stands for inliers and 1 for outliers.
- Return type:
numpy array of shape (n_samples,)
- abstract set_params(**params)[source]
Set the parameters of this estimator. See http://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html and sklearn/base.py for more information.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
**params (dict) – Estimator parameters.
- Returns:
self – Estimator instance.
- Return type:
estimator instance
RADAR.base_preprocessing_module module
Base Preprocessing Module that performs the main operations needed to preprocess every type of data
RADAR.base_utils_module module
RADAR.metrics_module module
RADAR.pos_process_module module
- RADAR.pos_process_module.compute_anomaly_proportion(labels)[source]
Calculates the proportion of anomalies in the data set.
Args:
labels: Binary anomaly labels (0: normal, 1: anomalous).
Returns:
proportion: Proportion of anomalies in the data.
- RADAR.pos_process_module.process_scores(d_scores, contamination)[source]
Calculate binary labels based on a contamination threshold.
- Parameters:
d_scores (array-like) – Decision scores.
contamination (float) – Proportion of outliers in the dataset (0.0 to 0.5).
- Returns:
Binary labels (0 for normal, 1 for anomaly).
- Return type:
np.ndarray
- RADAR.pos_process_module.process_scores_with_percentile(d_scores, contamination)[source]
Compute the threshold using the percentile method.
- Parameters:
d_scores (array-like) – Decision scores.
contamination (float) – Proportion of outliers in the dataset (0.0 to 0.5).
- Returns:
Threshold value.
- Return type:
float
- RADAR.pos_process_module.process_scores_with_threshold(d_scores)[source]
Compute the threshold using mean and standard deviation.
- Parameters:
d_scores (array-like) – Decision scores.
- Returns:
Threshold value.
- Return type:
float
- RADAR.pos_process_module.remove_low_confidence_anomalies(d_scores, anomalies, confidence_threshold=0.8)[source]
Removes anomalies with a decision score below a confidence threshold. Args: —– d_scores: List of decision scores. anomalies: Indices of detected anomalies. confidence_threshold: Confidence threshold (between 0 and 1).
Returns:
filtered_anomalies: List of anomaly indexes with high confidence.
RADAR.visualization_module module
Visualization Module
- class RADAR.visualization_module.DataVisualization(data, plot_technique='scatter', dim_reduction_technique=None, n_components=2, y_true=None, y_pred=None, color_map=None, point_size=5, opacity=0.8, heatmap_color='magma', subset_size_percent=0.2, **plot_kwargs)[source]
Bases:
object
- class RADAR.visualization_module.DataVisualizationScoresTS(scores)[source]
Bases:
objectClass for visualizing anomalies in temporal data from scores.
- visualize(method='percentile', threshold=0.95, top_k=None) plotly.graph_objects.Figure[source]
Visualize anomalies from anomaly scores without ground-truth labels.
Parameters:
- scoresarray-like
List or array with anomaly scores.
- methodstr, optional
Method to determine the threshold. Options: - “percentile” -> use the given percentile in ‘threshold’ - “std” -> mean + threshold*std - “topk” -> mark the ‘top_k’ highest scores
- thresholdfloat, optional
Value used as percentile (0-1) or number of standard deviations. E.g., 0.95 (95th percentile) or 3 (mean + 3*std).
- top_kint, optional
If method=”topk”, number of top anomalies to mark.