energy_fault_detector.core
This module contains class templates for most of the anomaly detection classes, such as anomaly scores, threshold selectors and data classes.
- class AnomalyScore(**kwargs)[source]
Bases:
BaseEstimator,TransformerMixin,SaveLoadMixin,ABCAnomaly score template
- abstractmethod fit(x, y=None)[source]
Fit the scorer.
- Parameters:
x (
Union[DataFrame,ndarray]) – numpy 2d array with differences between prediction and actual sensor valuesy (
Optional[Series]) – labels indicating whether sample is normal (True) or anomalous (False).
- Return type:
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') AnomalyScore
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$') AnomalyScore
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.
- class DataTransformer(**kwargs)[source]
Bases:
BaseEstimator,TransformerMixin,SaveLoadMixin,ABCDataTransformer template.
- abstractmethod fit(x, y=None)[source]
Fit the preprocessor with training data. Should set attributes feature_names_in_ and n_features_in_. If columns are selected/dropped, should also set feature_names_out_ and columns_dropped_.
- Parameters:
x (
DataFrame) – pandas dataframe with input datay (
Series) – (optional) labels indicating whether sample is normal (True) or anomalous (False).
- Return type:
- abstractmethod get_feature_names_out(input_features=None)[source]
Get output feature names for transformation.
- Return type:
List[str]
- Returns
feature_names_out : list/np array of str objects.
- abstractmethod inverse_transform(x)[source]
Implement inverse transform method
- Parameters:
x (
DataFrame) – input data.- Return type:
DataFrame
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') DataTransformer
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_inverse_transform_request(*, x: bool | None | str = '$UNCHANGED$') DataTransformer
Request metadata passed to the
inverse_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 toinverse_transformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toinverse_transform.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 ininverse_transform.
Returns
- selfobject
The updated object.
- set_transform_request(*, x: bool | None | str = '$UNCHANGED$') DataTransformer
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.
- class FaultDetectionResult(predicted_anomalies, reconstruction, recon_error, anomaly_score, bias_data=None, arcana_losses=None, tracked_bias=None)[source]
Bases:
objectClass to encapsulate results from the fault detection process.
- anomaly_score: Series
Series with predicted anomaly scores.
- arcana_losses: DataFrame | None = None
DataFrame containing recorded values for all losses in ARCANA. None if ARCANA was not run. Empty if losses were not tracked.
- bias_data: DataFrame | None = None
DataFrame with ARCANA results (ARCANA bias). None if ARCANA was not run.
- criticality(normal_idx=None, init_criticality=0, max_criticality=1000)[source]
Criticality based on the predicted anomalies.
- Parameters:
normal_idx (
Series|None) – A pandas Series with boolean values indicating normal operation, indexed by timestamp. Ignored if None.init_criticality (
int) – The initial criticality value. Defaults to 0.max_criticality (
int) – The maximum criticality value. Defaults to 1000.
- Return type:
Series
- classmethod load(directory, **kwargs)[source]
Loads the results from CSV files in the specified directory.
Restores MultiIndex if the results were saved with one.
- Parameters:
directory (
str|Path) – The directory where the CSV files are stored.kwargs – other keywords args for pd.read_csv (e.g., sep=’,’)
- Returns:
The loaded result object.
- Return type:
- predicted_anomalies: Series
Series with a predicted anomalies (bool).
- recon_error: DataFrame
DataFrame with reconstruction errors.
- reconstruction: DataFrame
DataFrame with reconstruction of the input data.
- save(directory, **kwargs)[source]
Saves the results to CSV files in the specified directory.
- Parameters:
directory (
str|Path) – The directory where the CSV files will be saved.kwargs – other keywords args for pd.DataFrame.to_csv (i.e. sep=’,’)
- Return type:
None
- tracked_bias: List[DataFrame] | None = None
List of DataFrames containing the ARCANA bias every 50th iteration. None if ARCANA was not run. Empty if bias was not tracked.
- class ModelMetadata(model_date, model_path, train_recon_error, val_recon_error=None)[source]
Bases:
objectClass to encapsulate metadata about the FaultDetector model.
- model_date: str
- model_path: str | Path
- train_recon_error: ndarray | DataFrame
- val_recon_error: ndarray | DataFrame | None = None
- class ThresholdSelector[source]
Bases:
BaseEstimator,ClassifierMixin,SaveLoadMixinTemplate for threshold selectors.
Finds the threshold (fit method) of the given reconstruction errors (x), to be considered anomalous. The predict method returns an array of boolean, indicating which samples of the input are anomalous.
- threshold
scores above the threshold is classified as anomaly, below is classified as normal.
- fit(x, y=None)[source]
Fit ThresholdSelector object on anomaly score values x and labels y to determine the score threshold. For prediction, every sample with a scores above this threshold is considered an anomaly.
- Parameters:
x (
Union[ndarray,Series]) – array or pandas Series with calculated anomaly scoresy (
Union[ndarray,Series]) – labels indicating whether sample is normal (True) or anomalous (False) Optional, if not given, we assume all data provided represents normal behaviour
- Return type:
- Returns:
The threshold selector
- predict(x, **kwargs)[source]
Return a boolean array indicating whether sample is anomalous.
- Parameters:
x (
Union[ndarray,Series]) – array with calculated anomaly scoreskwargs – other arguments for specific threshold selectors.
- Return type:
Union[ndarray,Series,Tuple[Union[ndarray,Series],Union[ndarray,Series]]]- Returns:
Boolean array where true = anomaly, false = normal
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') ThresholdSelector
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_predict_request(*, x: bool | None | str = '$UNCHANGED$') ThresholdSelector
Request metadata passed to the
predictmethod.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 topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.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 inpredict.
Returns
- selfobject
The updated object.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') ThresholdSelector
Request metadata passed to the
scoremethod.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 toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns
- selfobject
The updated object.
- energy_fault_detector.core.autoencoder
AutoencoderAutoencoder.is_conditionalAutoencoder.modelAutoencoder.encoderAutoencoder.historyAutoencoder.callbacksAutoencoder.__call__()Autoencoder.compile_model()Autoencoder.create_model()Autoencoder.encode()Autoencoder.epochs_completedAutoencoder.fit()Autoencoder.get_reconstruction_error()Autoencoder.load()Autoencoder.predict()Autoencoder.save()Autoencoder.summary()Autoencoder.tune()Autoencoder.tune_decoder()
split_inputs()