Skip to content

Commit 919458b

Browse files
author
sborms
committed
final PIG plots tweaks
1 parent 84f3cb1 commit 919458b

3 files changed

Lines changed: 161 additions & 160 deletions

File tree

cobra/evaluation/pigs_tables.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def plot_incidence(pig_tables: pd.DataFrame,
170170
ax.set_xlabel('{} bins' ''.format(variable), fontsize=16)
171171
ax.xaxis.set_tick_params(labelsize=14)
172172
plt.setp(ax.get_xticklabels(),
173-
rotation=45, ha="right", rotation_mode="anchor")
173+
rotation=90, ha="right", rotation_mode="anchor")
174174
ax.yaxis.set_tick_params(labelsize=14)
175175

176176
if model_type == "classification":
@@ -180,21 +180,19 @@ def plot_incidence(pig_tables: pd.DataFrame,
180180
ax.yaxis.set_major_formatter(
181181
FuncFormatter(lambda y, _: '{:.1%}'.format(y)))
182182
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.
183+
# If 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
187+
# y-axis range, to avoid that the minor avg. target differences are
188+
# spread out over the configured figure height, suggesting
189+
# incorrectly that there are big differences in avg. target across
190+
# the bins and versus the global avg. target.
191191
# (Motivation for the AND above: if on one end there IS enough
192192
# 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):
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)) / global_avg_target < 0.25)
195+
and (np.abs((min(df_plot['avg_target']) - global_avg_target)) / global_avg_target < 0.25)):
198196
ax.set_ylim(global_avg_target * 0.75,
199197
global_avg_target * 1.25)
200198

@@ -213,7 +211,7 @@ def plot_incidence(pig_tables: pd.DataFrame,
213211

214212
# Set labels & ticks
215213
ax2.set_xlabel('{} bins' ''.format(variable), fontsize=16)
216-
ax2.xaxis.set_tick_params(rotation=45, labelsize=14)
214+
ax2.xaxis.set_tick_params(rotation=90, labelsize=14)
217215

218216
ax2.yaxis.set_tick_params(labelsize=14)
219217
ax2.yaxis.set_major_formatter(
@@ -234,9 +232,9 @@ def plot_incidence(pig_tables: pd.DataFrame,
234232
title = "Incidence plot - " + variable
235233
else:
236234
title = "Mean target plot - " + variable
237-
fig.suptitle(title, fontsize=22, y=1.02)
235+
fig.suptitle(title, fontsize=22)
238236
ax.legend(frameon=False, bbox_to_anchor=(0., 1.01, 1., .102),
239-
loc=3, ncol=3, mode="expand", borderaxespad=0.,
237+
loc=3, ncol=1, mode="expand", borderaxespad=0.,
240238
prop={"size": 14})
241239

242240
# Set order of layers
@@ -245,5 +243,8 @@ def plot_incidence(pig_tables: pd.DataFrame,
245243

246244
del df_plot
247245

246+
plt.tight_layout()
247+
plt.margins(0.01)
248+
248249
# Show
249250
plt.show()

tutorials/tutorial_Cobra_linear_regression.ipynb

Lines changed: 114 additions & 114 deletions
Large diffs are not rendered by default.

tutorials/tutorial_Cobra_logistic_regression.ipynb

Lines changed: 29 additions & 29 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)