RADAR.static_data.algorithms

Submodules

RADAR.static_data.algorithms.pyod module

class RADAR.static_data.algorithms.pyod.PyodAnomalyDetection(**kwargs)[source]

Bases: BaseAnomalyDetection

decision_function(X)[source]

Predict raw anomaly score of X using the fitted detector.

Parameters:

X (numpy array of shape (n_samples, n_features)) – The training input samples. Sparse matrices are accepted only if they are supported by the base estimator.

Returns:

anomaly_scores – The anomaly score of the input samples.

Return type:

numpy array of shape (n_samples,)

evaluate(X, y=None)[source]

Evaluates the model on data X (and optionally y). Uses decision_function to get anomaly scores and predict to get labels. If y is provided, prints metrics using print_metrics.

Parameters:
  • X (numpy array of shape (n_samples, n_features)) – The input samples.

  • y (numpy array of shape (n_samples,), optional) – Ground truth labels (0 for normal, 1 for anomaly).

Returns:

results – Dictionary containing: - ‘scores’: anomaly scores from decision_function - ‘labels_preds’: predicted labels (0 for normal, 1 for anomaly) - ‘labels_true’: ground truth labels (if y is provided)

Return type:

dict

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

get_default_params(**params)[source]

Get DEFAULT parameters for this estimator, params is used to configure positional parameters in order to obtain default parameters of the object.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

get_params()[source]

Get parameters for this estimator.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

predict(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.

If label_parser is an attribute, then we execute the particular predict function

Parameters:

X (numpy array of shape (n_samples, n_features)) – The input samples. Sparse matrices are accepted only if they are supported by the base estimator.

Returns:

anomaly_scores – The anomaly score of the input samples.

Return type:

numpy array of shape (n_samples,)

classmethod register_algorithm(name, model_class)[source]

Register a new algorithm in the class. :param - name: The name of the new algorithm. :type - name: str :param - model_class: The class implementing the anomaly detection model. :type - model_class: class

The class should have:
  • An __init__ method that accepts model-specific parameters.

  • A fit(X, y) method to train the model.

  • A predict(X) method to make predictions.

  • Optionally, a decision_function(X) for scoring anomalies.

set_params(**params)[source]

Set the parameters of this estimator. :returns: self :rtype: object

RADAR.static_data.algorithms.sklearn module

class RADAR.static_data.algorithms.sklearn.SkLearnAnomalyDetection(**kwargs)[source]

Bases: BaseAnomalyDetection

decision_function(X)[source]

Predict raw anomaly score of X using the fitted detector.

Parameters:

X (numpy array of shape (n_samples, n_features)) – The training input samples.

Returns:

anomaly_scores – The anomaly score of the input samples.

Return type:

numpy array of shape (n_samples,)

evaluate(X, y=None)[source]

Evaluates the model on data X (and optionally y). Uses decision_function to get anomaly scores and predict to get labels. Note: sklearn uses -1 for outliers and +1 for inliers, which are converted to 0/1 for metrics. If y is provided, prints metrics using print_metrics.

Parameters:
  • X (numpy array of shape (n_samples, n_features)) – The input samples.

  • y (numpy array of shape (n_samples,), optional) – Ground truth labels (0 for normal, 1 for anomaly). Note: If y uses -1/+1 format, it will be converted to 0/1 automatically.

Returns:

results – Dictionary containing: - ‘scores’: anomaly scores from decision_function - ‘labels_preds’: predicted labels (0 for normal, 1 for anomaly) - ‘labels_true’: ground truth labels

Return type:

dict

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

get_default_params(**params)[source]

Get DEFAULT parameters for this estimator, params is used to configure positional parameters in order to obtain default parameters of the object.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

get_params()[source]

Get parameters for this estimator.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

predict(X)[source]

Predict labels (1 inlier, -1 outlier) of X according to fitted model.

Parameters:

X (array-like of shape (n_samples, n_features)) – The data matrix.

Returns:

is_inlier – Returns -1 for anomalies/outliers and +1 for inliers.

Return type:

ndarray of shape (n_samples,)

classmethod register_algorithm(name, model_class)[source]

Register a new algorithm in the class. :param - name: The name of the new algorithm. :type - name: str :param - model_class: The class implementing the anomaly detection model. :type - model_class: class

The class should have:
  • An __init__ method that accepts model-specific parameters.

  • A fit(X, y) method to train the model.

  • A predict(X) method to make predictions.

  • Optionally, a decision_function(X) for scoring anomalies.

set_params(**params)[source]

Set the parameters of this estimator. :returns: self :rtype: object

Module contents