energy_fault_detector.anomaly_scores
Anomaly score classes.
- class MahalanobisScore(pca=True, pca_min_var=0.9, mcd_support_fraction=0.9, scale=False)[source]
Bases:
AnomalyScoreCalculate mahalanobis scores using sklearn MinCovDet und optionally a PCA to accelerate calculations.
- Parameters:
pca (
bool) – boolean to indicate whether PCA should be done before determining the covariance. Default true.pca_min_var (
float) – parameter for PCA, variance to keep. Default 0.9mcd_support_fraction (
float) – parameter for Minimum Covariance Determinant estimation. Default 0.9scale (
bool) – If True, std of the training/fit reconstruction errors will be used to scale recon errors before applying MinCovDet. Default: False
Configuration example:
train: anomaly_score: name: mahalanobis params: pca: True pca_min_var: 0.9 mcd_support_fraction: 0.9 scale: False- fit(x, y=None)[source]
Fit MinCovDet object to determine Mahalanobis distance.
- Parameters:
x (
Union[DataFrame,ndarray]) – numpy 2d array or pandas DataFrame with differences between prediction and actual sensor values.y (
Optional[Series]) – not used, labels indicating whether sample is normal (True) or anomalous (False).
- Return type:
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') MahalanobisScore
Request metadata passed to the
fitmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.Parameters
- xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
xparameter infit.
Returns
- selfobject
The updated object.
- set_transform_request(*, x: bool | None | str = '$UNCHANGED$') MahalanobisScore
Request metadata passed to the
transformmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.Parameters
- xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
xparameter intransform.
Returns
- selfobject
The updated object.
- transform(x)[source]
Calculate Mahalanobis distance from x.
- Parameters:
x (
Union[DataFrame,ndarray]) – numpy 2d array or pandas Dataframe with differences between prediction and actual sensor values- Return type:
Series- Returns:
Mahalanobis distance for each sample. Output is a pandas Series if input was a pandas DataFrame
- class RMSEScore(scale=True, **kwargs)[source]
Bases:
AnomalyScoreCalculate the RMSE of given reconstruction errors.
- scale
If True, mean and std of the training/fit reconstruction errors will be used to standardize recon errors during transform. Default: True
Configuration example:
train: anomaly_score: name: rmse params: scale: false- fit(x, y=None)[source]
Calculate standard deviation and mean on training data
- Parameters:
x (
Union[DataFrame,ndarray]) – numpy 2d array with differences between prediction and actual sensor valuesy (
Optional[Series]) – not used, labels indicating whether sample is normal (True) or anomalous (False).
- Return type:
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') RMSEScore
Request metadata passed to the
fitmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.Parameters
- xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
xparameter infit.
Returns
- selfobject
The updated object.
- set_transform_request(*, x: bool | None | str = '$UNCHANGED$') RMSEScore
Request metadata passed to the
transformmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.Parameters
- xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
xparameter intransform.
Returns
- selfobject
The updated object.