Skip to content

Commit 53a9858

Browse files
author
Sander Vanden Hautte
committed
PIG plot fix: avoiding the
exaggeration of avg_target differences if differences across bins and vs global avg target is small (issue #32).
1 parent 51e0498 commit 53a9858

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

cobra/evaluation/pigs_tables.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,24 @@ def plot_incidence(pig_tables: pd.DataFrame,
179179
ax.set_yticks(np.arange(0, max(df_plot['avg_target'])+0.05, 0.05))
180180
ax.yaxis.set_major_formatter(
181181
FuncFormatter(lambda y, _: '{:.1%}'.format(y)))
182+
elif model_type == "regression":
183+
# If both the difference between the highest avg target of all bins
184+
# versus the global avg target AND the difference between the
185+
# lowest avg target versus the global avg target are both smaller
186+
# than 25% of the global avg target itself, we increase the y
187+
# axis range, to avoid that the minor avg target differences are
188+
# spread out over the configure figure height, suggesting
189+
# incorrectly that there are big differences in avg target across
190+
# the bins and versus the global avg target.
191+
# (Motivation for the AND above: if on one end there IS enough
192+
# difference, the effect that we discuss here does not occur.)
193+
global_avg_target = max(df_plot['global_avg_target']) # series of same number, for every bin.
194+
if (np.abs((max(df_plot['avg_target']) - global_avg_target))
195+
/ global_avg_target < 0.25) \
196+
and (np.abs((min(df_plot['avg_target']) - global_avg_target))
197+
/ global_avg_target < 0.25):
198+
ax.set_ylim(global_avg_target * 0.75,
199+
global_avg_target * 1.25)
182200

183201
# Remove ticks but keep the labels
184202
ax.tick_params(axis='both', which='both', length=0)

0 commit comments

Comments
 (0)