energy_fault_detector.utils.visualisation
Visualisation functions.
- animate_bias(bias_list, selected_column_names, filename='arcana_bias.gif', figsize=(8, 8))[source]
Plots biases as a bar plot and animates it over the iterations.
- Parameters:
bias_list (
List[DataFrame]) – A list of pandas DataFrames containing ARCANA biases recorded over the iterations.selected_column_names (
List[str]) – Names of the features which should be plotted.filename (
str) – Name of the GIF file. Defaults to ‘arcana_bias.gif’.figsize (
Tuple) – Size of the figure if a new one is created. Defaults to (8, 8).
- animate_corrected_input(corrected_list, selected_column_names, initial_input, expected_result=None, filename='arcana_corrected_input.gif', figsize=(8, 8))[source]
Plots graphs of ARCANA corrected inputs, which are the initial_input + bias, and animates them.
- Parameters:
corrected_list (
List[DataFrame]) – A list of pandas DataFrames containing ARCANA corrected inputs recorded over the iterations.selected_column_names (
List[str]) – Names of the features which should be plotted.initial_input (
DataFrame) – Input at the starting point of the ARCANA optimization.expected_result (
DataFrame) – Expected normal behavior for debugging and verifying results. Defaults to None.filename (
str) – Name of the GIF file. Defaults to ‘arcana_corrected_input.gif’.figsize (
Tuple) – Size of the figure if a new one is created. Defaults to (8, 8).
- plot_arcana_importance_series(importances, num_features=5, anomaly_events=None, ax=None, figsize=(8, 3), **subplot_kwargs)[source]
Plots the importance time series for the features with the highest average importance across all timestamps.
- Parameters:
importances (
List[DataFrame]) – Contains pandas DataFrames with importance values for different features (columns) across a range of timestamps (index).num_features (
Optional[int]) – Number of features to plot for each event. The features with the highest maximum importance across all analyzed event timestamps are selected. Defaults to 5.anomaly_events (
Optional[DataFrame]) – DataFrame with columns ‘start’, ‘end’, and ‘duration’ describing detected anomaly events. Defaults to None.figsize (
Optional[Tuple[float,float]]) – Size of the figure if a new one is created. Defaults to (8, 8).ax (
Optional[Axes]) – Axes object to plot on. If None, a new figure and axes will be created.**subplot_kwargs – Additional keyword arguments for plt.subplots().
- Returns:
None
- plot_arcana_losses(losses, figsize=(8, 8))[source]
Plots the graphs for the ARCANA losses: Loss 1, Loss 2, and Combined Loss.
- Parameters:
losses (
DataFrame) – A DataFrame with iteration numbers as index and the columns representing the losses.figsize (
Tuple) – Size of the figure if a new one is created. Defaults to (8, 8).
- Return type:
None
- plot_arcana_mean_importances(importances, top_n_features=10, figsize=(8, 8), ax=None, **subplot_kwargs)[source]
Plot the ARCANA importances as a horizontal bar plot.
- Parameters:
importances (
Series) – Series containing the ARCANA importances of the features.top_n_features (
int) – Number of features to plot. Defaults to 10.figsize (
Tuple) – Size of the figure if a new one is created. Defaults to (8, 8).ax (
Axes) – Axes object to plot on. If None, a new figure and axes will be created.**subplot_kwargs – Additional keyword arguments for plt.subplots().
- Returns:
The figure and axes containing the plot for further customization if needed.
- Return type:
Tuple[Figure,Axes]
- plot_learning_curve(model, ax=None, label='', **subplot_kwargs)[source]
Plot the learning curve of the specified model.
- Parameters:
model (
Union[Autoencoder,FaultDetector]) – The model for which to plot the learning curve.ax (
Axes) – Axes to plot the learning curve on. Defaults to None.label (
str) – Label for the learning curve. Defaults to ‘’.subplot_kwargs (dict, optional) – Additional keyword arguments for subplots, if no axes are passed.
- Returns:
The figure and axes containing the plot.
- Return type:
Tuple[Figure,Axes]
- plot_reconstruction(data, reconstruction, features_to_plot=None, height_multiplier=1.5, original_scale=True)[source]
Plots the original dataset and its reconstruction.
Notes
Can result in a very large plot, if the dataset contains many columns/features. Use the
features_to_plot parameter to specify which columns to plot.
For MultiIndex data (e.g. multiple devices), pass data for a single group/device, i.e.
df.loc[device_id]to select one device before plotting.
- Parameters:
data (
DataFrame) – DataFrame containing the original data.reconstruction (
DataFrame) – DataFrame containing the reconstructed data.features_to_plot (
Optional[List[str]]) – List of features to plot. Defaults to None (all features).height_multiplier (
float) – Multiplier for the vertical size of the figure. Defaults to 1.5.original_scale (
bool) – Whether to scale the y-axis using the input data. Defaults to True. If true, the y limits are set to minimum - std, maximum + std for each feature plotted.
- Returns:
The figure and axes containing the plots, for further customization if needed.
- Return type:
Tuple[Figure,Axes]
- plot_reconstruction_with_model(model, data, features_to_plot=None, height_multiplier=1.5, original_scale=True)[source]
- Plots the data and its reconstruction using the provided model. Similar to plot_reconstruction, but uses the
‘model.predict’ method to get the reconstruction. Counter values are plottet as diffs or rates with their reconstruction.
Note
For MultiIndex data (e.g. multiple devices), pass data for a single group/device. Use
df.loc[device_id]to select one device before plotting.- Parameters:
model (
FaultDetector) – Fitted model with data_preprocessor and autoencoder.data (
DataFrame) – Raw input data.features_to_plot (
Optional[List[str]]) – Columns to plot. If None, uses reconstruction columns.height_multiplier (
float) – Vertical scaling for the figure. Defaults to 1.5.original_scale (
bool) – If True, y-limits are based on the observed plot-series (min-std, max+std). Defaults to True.
- Returns:
The figure and axes.
- Return type:
Tuple[Figure,Axes]
- plot_score_with_threshold(model, data, normal_index=None, ax=None, figsize=(8, 3), show_predicted_anomaly=False, show_threshold=True, show_criticality=False, max_criticality=144, score_color=None, anomaly_color=None, criticality_color='C2', marker_size=1, threshold_color='k', **subplot_kwargs)[source]
Plots the anomaly scores of the AnomalyDetector model along with the threshold for the provided data.
Note
For MultiIndex data (e.g. multiple devices), pass data for a single group/device. Use
df.loc[device_id]to select one device before plotting.- Parameters:
model (
FaultDetector) – The anomaly detection model used to compute the scores.data (
DataFrame) – DataFrame containing the data for which scores are computed.normal_index (
Series) – Boolean series indicating whether the data points have a normal status or not.ax (
Axes) – Axes object to plot on. If None, a new figure and axes will be created.figsize (
Tuple[float,float]) – Size of the figure if a new one is created. Defaults to (8, 3).show_predicted_anomaly (
bool) – Whether to show the predicted anomaly scores. Defaults to False.show_threshold (
bool) – Whether to show the threshold scores. Defaults to True.show_criticality (
bool) – Whether to show the criticality counter. Defaults to False.max_criticality (
int) – If show_criticality is True, the maximum value of the criticality counter can be specified. Defaults to 144 (one day of 10 min timestamps).score_color (
Optional[str]) – Color to use for the anomaly score.anomaly_color (
Optional[str]) – Color to use for the anomalous data points (using normal_index).criticality_color (
Optional[str]) – Color to use for the criticality counter if show_criticality is True. Defaults to ‘C2’.marker_size (
Optional[int]) – Dot size in the scatter plot. Defaults to 1.threshold_color (
Optional[str]) – Color to use for the threshold.**subplot_kwargs – Additional keyword arguments for plt.subplots().
- Returns:
The figure and axes containing the plot for further customization if needed.
- Return type:
Tuple[Figure,Axes]