-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
Copy pathplot_improper_preprocessing.py
76 lines (62 loc) · 3.1 KB
/
plot_improper_preprocessing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import matplotlib.pyplot as plt
def make_bracket(s, xy, textxy, width, ax):
annotation = ax.annotate(
s, xy, textxy, ha="center", va="center", size=20,
arrowprops=dict(arrowstyle="-[", fc="w", ec="k",
lw=2,), bbox=dict(boxstyle="square", fc="w"))
annotation.arrow_patch.get_arrowstyle().widthB = width
def plot_improper_processing():
fig, axes = plt.subplots(2, 1, figsize=(15, 10))
for axis in axes:
bars = axis.barh([0, 0, 0], [11.9, 2.9, 4.9], left=[0, 12, 15],
color=['white', 'grey', 'grey'], hatch="//",
align='edge', edgecolor='k')
bars[2].set_hatch(r"")
axis.set_yticks(())
axis.set_frame_on(False)
axis.set_ylim(-.1, 6)
axis.set_xlim(-0.1, 20.1)
axis.set_xticks(())
axis.tick_params(length=0, labeltop=True, labelbottom=False)
axis.text(6, -.3, "training folds",
fontdict={'fontsize': 14}, horizontalalignment="center")
axis.text(13.5, -.3, "validation fold",
fontdict={'fontsize': 14}, horizontalalignment="center")
axis.text(17.5, -.3, "test set",
fontdict={'fontsize': 14}, horizontalalignment="center")
make_bracket("scaler fit", (7.5, 1.3), (7.5, 2.), 15, axes[0])
make_bracket("SVC fit", (6, 3), (6, 4), 12, axes[0])
make_bracket("SVC predict", (13.4, 3), (13.4, 4), 2.5, axes[0])
axes[0].set_title("Cross validation")
axes[1].set_title("Test set prediction")
make_bracket("scaler fit", (7.5, 1.3), (7.5, 2.), 15, axes[1])
make_bracket("SVC fit", (7.5, 3), (7.5, 4), 15, axes[1])
make_bracket("SVC predict", (17.5, 3), (17.5, 4), 4.8, axes[1])
def plot_proper_processing():
fig, axes = plt.subplots(2, 1, figsize=(15, 8))
for axis in axes:
bars = axis.barh([0, 0, 0], [11.9, 2.9, 4.9],
left=[0, 12, 15], color=['white', 'grey', 'grey'],
hatch="//", align='edge', edgecolor='k')
bars[2].set_hatch(r"")
axis.set_yticks(())
axis.set_frame_on(False)
axis.set_ylim(-.1, 4.5)
axis.set_xlim(-0.1, 20.1)
axis.set_xticks(())
axis.tick_params(length=0, labeltop=True, labelbottom=False)
axis.text(6, -.3, "training folds", fontdict={'fontsize': 14},
horizontalalignment="center")
axis.text(13.5, -.3, "validation fold", fontdict={'fontsize': 14},
horizontalalignment="center")
axis.text(17.5, -.3, "test set", fontdict={'fontsize': 14},
horizontalalignment="center")
make_bracket("scaler fit", (6, 1.3), (6, 2.), 12, axes[0])
make_bracket("SVC fit", (6, 3), (6, 4), 12, axes[0])
make_bracket("SVC predict", (13.4, 3), (13.4, 4), 2.5, axes[0])
axes[0].set_title("Cross validation")
axes[1].set_title("Test set prediction")
make_bracket("scaler fit", (7.5, 1.3), (7.5, 2.), 15, axes[1])
make_bracket("SVC fit", (7.5, 3), (7.5, 4), 15, axes[1])
make_bracket("SVC predict", (17.5, 3), (17.5, 4), 4.8, axes[1])
fig.subplots_adjust(hspace=.3)