Skip to content

Commit

Permalink
avoid failure of plot_feature_outlier_image (#774)
Browse files Browse the repository at this point in the history
* avoid failure of plot_feature_outlier_image

I call the function this way:
plot_feature_outlier_image(preds,  # output of an prediction
                                   ds, # my set of images
                                   X_recon=recon, # reconstructed set of images
                                   max_instances=5,       # max nb of instances to display
                                   n_channels=3,          # number of channels of the images
                                   figsize=(20,10),
                                   outliers_only=True)    # only show outlier predictions. this function fails when no outlier is detected and parameter set to True
In case there is no outlieres detected and the parameter outliers_only is set to True, then the function fails, because it calls plt.subplots(nrows=0, ....). 0 rows throws the error.

* remove whitespace in blank line

* Add warning message to plot_feature_outlier_image

---------

Co-authored-by: Alex Athorne <[email protected]>
  • Loading branch information
signupatgmx and mauicv authored Apr 24, 2023
1 parent 8a945ce commit fa8f8b6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions alibi_detect/utils/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pandas as pd
from sklearn.metrics import roc_curve, auc
from typing import Dict, Union
import warnings


def plot_instance_score(preds: Dict,
Expand Down Expand Up @@ -77,6 +78,11 @@ def plot_feature_outlier_image(od_preds: Dict,
instance_ids = list(range(len(od_preds['data']['is_outlier'])))
n_instances = min(max_instances, len(instance_ids))
instance_ids = instance_ids[:n_instances]

if outliers_only and n_instances == 0:
warnings.warn('No outliers found!', UserWarning)
return

n_cols = 2

if n_channels == 3:
Expand Down

0 comments on commit fa8f8b6

Please sign in to comment.