Skip to content

Commit 242585b

Browse files
author
sborms
committed
mainly prettifying some graphs
1 parent 83b194b commit 242585b

5 files changed

Lines changed: 190 additions & 165 deletions

File tree

cobra/evaluation/evaluator.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,14 @@ def plot_roc_curve(self, path: str=None, dim: tuple=(12, 8)):
187187
label="ROC curve (area = {s:.3})".format(s=auc))
188188

189189
ax.plot([0, 1], [0, 1], color="darkorange", linewidth=3,
190-
linestyle="--")
191-
ax.set_xlabel("False Positive Rate", fontsize=15)
192-
ax.set_ylabel("True Positive Rate", fontsize=15)
190+
linestyle="--", label="random selection")
191+
ax.set_xlabel("False positive rate", fontsize=15)
192+
ax.set_ylabel("True positive rate", fontsize=15)
193193
ax.legend(loc="lower right")
194194
ax.set_title("ROC curve", fontsize=20)
195195

196+
ax.set_ylim([0, 1])
197+
196198
if path:
197199
plt.savefig(path, format="png", dpi=300, bbox_inches="tight")
198200

@@ -224,6 +226,8 @@ def plot_confusion_matrix(self, path: str=None, dim: tuple=(12, 8),
224226
fmt="s", cmap="Blues",
225227
xticklabels=labels, yticklabels=labels)
226228
ax.set_title("Confusion matrix", fontsize=20)
229+
plt.ylabel('True labels', fontsize=15)
230+
plt.xlabel('Predicted labels', fontsize=15)
227231

228232
if path:
229233
plt.savefig(path, format="png", dpi=300, bbox_inches="tight")
@@ -256,13 +260,13 @@ def plot_cumulative_response_curve(self, path: str=None, dim: tuple=(12, 8)):
256260

257261
plt.bar(x_labels[::-1], lifts, align="center",
258262
color="cornflowerblue")
259-
plt.ylabel("response (%)", fontsize=16)
260-
plt.xlabel("decile", fontsize=16)
263+
plt.ylabel("Response (%)", fontsize=15)
264+
plt.xlabel("Decile", fontsize=15)
261265
ax.set_xticks(x_labels)
262266
ax.set_xticklabels(x_labels)
263267

264268
plt.axhline(y=inc_rate*100, color="darkorange", linestyle="--",
265-
xmin=0.05, xmax=0.95, linewidth=3, label="Incidence")
269+
xmin=0.05, xmax=0.95, linewidth=3, label="incidence")
266270

267271
# Legend
268272
ax.legend(loc="upper right")
@@ -305,13 +309,13 @@ def plot_lift_curve(self, path: str=None, dim: tuple=(12, 8)):
305309

306310
plt.bar(x_labels[::-1], lifts, align="center",
307311
color="cornflowerblue")
308-
plt.ylabel("lift", fontsize=16)
309-
plt.xlabel("decile", fontsize=16)
312+
plt.ylabel("Lift", fontsize=15)
313+
plt.xlabel("Decile", fontsize=15)
310314
ax.set_xticks(x_labels)
311315
ax.set_xticklabels(x_labels)
312316

313317
plt.axhline(y=1, color="darkorange", linestyle="--",
314-
xmin=0.05, xmax=0.95, linewidth=3, label="Baseline")
318+
xmin=0.05, xmax=0.95, linewidth=3, label="baseline")
315319

316320
# Legend
317321
ax.legend(loc="upper right")
@@ -354,7 +358,9 @@ def plot_cumulative_gains(self, path: str=None, dim: tuple=(12, 8)):
354358

355359
# Format axes
356360
ax.set_xlim([0, 100])
357-
ax.set_ylim([0, 105])
361+
ax.set_ylim([0, 100])
362+
plt.ylabel("Gain", fontsize=15)
363+
plt.xlabel("Percentage", fontsize=15)
358364

359365
# Format ticks
360366
ticks_loc_y = ax.get_yticks().tolist()

cobra/evaluation/pigs_tables.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def compute_pig_table(basetable: pd.DataFrame,
7070
global_avg_target = basetable[target_column_name].mean()
7171

7272
# group by the binned variable, compute the incidence
73-
# (=mean of the target for the given bin) and compute the bin size
73+
# (= mean of the target for the given bin) and compute the bin size
7474
# (e.g. COUNT(id_column_name)). After that, rename the columns
7575
res = (basetable.groupby(predictor_column_name)
7676
.agg({target_column_name: "mean", id_column_name: "size"})
@@ -165,9 +165,9 @@ def plot_incidence(pig_tables: pd.DataFrame,
165165
ax.plot(np.nan, "#939598", linewidth=6, label='bin size')
166166

167167
# Set labels & ticks
168-
ax.set_ylabel('incidence' if model_type == "classification" else "mean target value",
168+
ax.set_ylabel('Incidence' if model_type == "classification" else "Mean target value",
169169
fontsize=16)
170-
ax.set_xlabel('{} bins' ''.format(variable), fontsize=16)
170+
ax.set_xlabel("Bins", fontsize=15)
171171
ax.xaxis.set_tick_params(labelsize=14)
172172
plt.setp(ax.get_xticklabels(),
173173
rotation=45, ha="right", rotation_mode="anchor")
@@ -210,13 +210,13 @@ def plot_incidence(pig_tables: pd.DataFrame,
210210
align='center', color="#939598", zorder=1)
211211

212212
# Set labels & ticks
213-
ax2.set_xlabel('{} bins' ''.format(variable), fontsize=16)
213+
ax2.set_xlabel("Bins", fontsize=15)
214214
ax2.xaxis.set_tick_params(rotation=45, labelsize=14)
215215

216216
ax2.yaxis.set_tick_params(labelsize=14)
217217
ax2.yaxis.set_major_formatter(
218218
FuncFormatter(lambda y, _: '{:.1%}'.format(y)))
219-
ax2.set_ylabel('population size', fontsize=16)
219+
ax2.set_ylabel('Population size', fontsize=15)
220220
ax2.tick_params(axis='y', colors="#939598")
221221
ax2.yaxis.label.set_color('#939598')
222222

@@ -229,10 +229,11 @@ def plot_incidence(pig_tables: pd.DataFrame,
229229

230230
# Title & legend
231231
if model_type == "classification":
232-
title = "Incidence plot - " + variable
232+
title = "Incidence plot"
233233
else:
234-
title = "Mean target plot - " + variable
235-
fig.suptitle(title, fontsize=22)
234+
title = "Mean target plot"
235+
fig.suptitle(title, fontsize=20)
236+
plt.title(variable, fontsize=17)
236237
ax.legend(frameon=False, bbox_to_anchor=(0., 1.01, 1., .102),
237238
loc=3, ncol=1, mode="expand", borderaxespad=0.,
238239
prop={"size": 14})

cobra/evaluation/plotting_utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ def plot_univariate_predictor_quality(df_metric: pd.DataFrame,
4747

4848
# Set pretty axis
4949
sns.despine(ax=ax, right=True)
50+
plt.ylabel("Predictor", fontsize=15)
51+
plt.xlabel(metric, fontsize=15)
5052

5153
# Remove white lines from the second axis
5254
ax.grid(False)
5355

5456
if path is not None:
5557
plt.savefig(path, format="png", dpi=300, bbox_inches="tight")
5658

59+
plt.gca().legend().set_title("")
60+
5761
plt.show()
5862

5963
def plot_correlation_matrix(df_corr: pd.DataFrame,
@@ -71,7 +75,7 @@ def plot_correlation_matrix(df_corr: pd.DataFrame,
7175
Path to store the figure.
7276
"""
7377
fig, ax = plt.subplots(figsize=dim)
74-
ax = sns.heatmap(df_corr, cmap='Blues')
78+
ax = sns.heatmap(df_corr, cmap="Blues")
7579
ax.set_title("Correlation matrix", fontsize=20)
7680

7781
if path is not None:
@@ -150,7 +154,7 @@ def plot_performance_curves(model_performance: pd.DataFrame,
150154
fig.suptitle('Performance curves forward feature selection',
151155
fontsize=20)
152156
plt.title("Metric: "+metric_name, fontsize=15, loc="left")
153-
plt.ylabel('Model performance')
157+
plt.ylabel('Model performance', fontsize=15)
154158

155159
if path is not None:
156160
plt.savefig(path, format="png", dpi=300, bbox_inches="tight")
@@ -184,8 +188,10 @@ def plot_variable_importance(df_variable_importance: pd.DataFrame,
184188
else:
185189
ax.set_title("Variable importance", fontsize=20)
186190

187-
# Set Axis - make them pretty
191+
# Make pretty axis
188192
sns.despine(ax=ax, right=True)
193+
plt.ylabel('Predictor', fontsize=15)
194+
plt.xlabel('Importance', fontsize=15)
189195

190196
# Remove white lines from the second axis
191197
ax.grid(False)

tutorials/tutorial_Cobra_linear_regression.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@
350350
"cell_type": "markdown",
351351
"metadata": {},
352352
"source": [
353-
"#### The first part focusses on preparing the predictors for modelling by:\n",
353+
"#### The first part focuses on preparing the predictors for modelling by:\n",
354354
"\n",
355-
"1. Defining the ID column, the target, discrete and contineous variables.\n",
355+
"1. Defining the ID column, the target, discrete and continuous variables.\n",
356356
"\n",
357357
"2. Splitting the dataset into training, selection and validation datasets.\n",
358358
"\n",

0 commit comments

Comments
 (0)