Skip to content

Commit fa8f8b6

Browse files
signupatgmxmauicv
andauthored
avoid failure of plot_feature_outlier_image (#774)
* 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]>
1 parent 8a945ce commit fa8f8b6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

alibi_detect/utils/visualize.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pandas as pd
44
from sklearn.metrics import roc_curve, auc
55
from typing import Dict, Union
6+
import warnings
67

78

89
def plot_instance_score(preds: Dict,
@@ -77,6 +78,11 @@ def plot_feature_outlier_image(od_preds: Dict,
7778
instance_ids = list(range(len(od_preds['data']['is_outlier'])))
7879
n_instances = min(max_instances, len(instance_ids))
7980
instance_ids = instance_ids[:n_instances]
81+
82+
if outliers_only and n_instances == 0:
83+
warnings.warn('No outliers found!', UserWarning)
84+
return
85+
8086
n_cols = 2
8187

8288
if n_channels == 3:

0 commit comments

Comments
 (0)