energy_fault_detector.utils.visualisation
Visualisation functions.
- animate_bias(bias_list, selected_column_names, filename='arcana_bias.gif', figsize=(8, 8))
Plots biases as a bar plot and animates it over the iterations.
- Parameters:
bias_list (List[pd.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, optional) – Name of the GIF file. Defaults to ‘arcana_bias.gif’.
figsize (Tuple[float, float], optional) – 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))
Plots graphs of ARCANA corrected inputs, which are the initial_input + bias, and animates them.
- Parameters:
corrected_list (List[pd.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 (pd.DataFrame) – Input at the starting point of the ARCANA optimization.
expected_result (Optional[pd.DataFrame], optional) – Expected normal behavior for debugging and verifying results. Defaults to None.
filename (str, optional) – Name of the GIF file. Defaults to ‘arcana_corrected_input.gif’.
figsize (Tuple[float, float], optional) – 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)
Plots the importance time series for the features with the highest average importance across all timestamps.
- Parameters:
importances (List[pd.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[pd.DataFrame]) – DataFrame with columns ‘start’, ‘end’, and ‘duration’ describing detected anomaly events. Defaults to None.
figsize (Tuple[float, float], optional) – Size of the figure if a new one is created. Defaults to (8, 8).
ax (Optional[plt.Axes], optional) – 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))
Plots the graphs for the ARCANA losses: Loss 1, Loss 2, and Combined Loss.
- plot_arcana_mean_importances(importances, top_n_features=10, figsize=(8, 8), ax=None, **subplot_kwargs)
Plot the ARCANA importances as a horizontal bar plot.
- Parameters:
importances (pd.Series) – Series containing the ARCANA importances of the features.
top_n_features (int, optional) – Number of features to plot. Defaults to 10.
figsize (Tuple[float, float], optional) – Size of the figure if a new one is created. Defaults to (8, 8).
ax (Optional[plt.Axes], optional) – 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[plt.Figure, plt.Axes]
- plot_learning_curve(model, ax=None, label='', **subplot_kwargs)
Plot the learning curve of the specified model.
- Parameters:
model (Union[Autoencoder, FaultDetector]) – The model for which to plot the learning curve.
ax (Optional[plt.Axes], optional) – Axes to plot the learning curve on. Defaults to None.
label (str, optional) – 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[plt.Figure, plt.Axes]
- plot_reconstruction(data, reconstruction, features_to_plot=None, height_multiplier=1.5, original_scale=True)
Plots the original dataset and its reconstruction.
Note: 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.
- Parameters:
data (pd.DataFrame) – DataFrame containing the original data.
reconstruction (pd.DataFrame) – DataFrame containing the reconstructed data.
features_to_plot (Optional[List[str]], optional) – List of features to plot. Defaults to None (all features).
height_multiplier (float, optional) – Multiplier for the vertical size of the figure. Defaults to 1.5.
original_scale (bool, optional) – 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[plt.Figure, plt.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', threshold_color='k', **subplot_kwargs)
Plots the anomaly scores of the AnomalyDetector model along with the threshold for the provided data.
- Parameters:
model (FaultDetector) – The anomaly detection model used to compute the scores.
data (pd.DataFrame) – DataFrame containing the data for which scores are computed.
normal_index (pd.Series) – Boolean series indicating whether the data points have a normal status or not.
ax (Optional[plt.Axes], optional) – Axes object to plot on. If None, a new figure and axes will be created.
figsize (Tuple[float, float], optional) – Size of the figure if a new one is created. Defaults to (8, 3).
show_predicted_anomaly (bool, optional) – Whether to show the predicted anomaly scores. Defaults to False.
show_threshold (bool, optional) – Whether to show the threshold scores. Defaults to True.
show_criticality (bool, optional) – Whether to show the criticality counter. Defaults to False.
max_criticality (int optional) – 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], optional) – Color to use for the anomaly score.
anomaly_color (Optional[str], optional) – Color to use for the anomalous data points (using normal_index).
criticality_color (Optional[str], optional) – Color to use for the criticality counter if show_criticality is True. Defaults to ‘C2’.
threshold_color (Optional[str], optional) – 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[plt.Figure, plt.Axes]