-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvisualization.py
More file actions
executable file
·150 lines (134 loc) · 5.28 KB
/
visualization.py
File metadata and controls
executable file
·150 lines (134 loc) · 5.28 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import math
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
def heatmap(dataset, subgroups, target_columns, translations, cols, group_size, include_dataset):
sets = [dataset] + subgroups[:group_size] if include_dataset else subgroups[:group_size]
titles = ['Dataset'] + [str(s.description) for s in subgroups[:group_size]] if include_dataset else \
[str(s.description) for s in subgroups[:group_size]]
fig = make_subplots(rows=math.ceil((group_size + 1) / cols), cols=cols,
subplot_titles=titles,
vertical_spacing=0.39)
for i, subgroup in enumerate(sets):
fig.add_trace(
go.Heatmap(z=subgroup.target, x=translations[target_columns[1]], y=translations[target_columns[0]],
legendgroup=str(i)),
row=math.floor(i / cols) + 1, col=(i % cols) + 1
)
# fig.update_xaxes(range=[dataset.data[target_columns[0]].min(), dataset.data[target_columns[0]].max()])
# fig.update_yaxes(range=[dataset.data[target_columns[1]].min(), dataset.data[target_columns[1]].max()])
fig.update_layout(
showlegend=False
)
annotations = [a.to_plotly_json() for a in fig["layout"]["annotations"]]
annotations.extend([
dict(
x=0.5,
y=-0.15,
showarrow=False,
text=target_columns[0],
xref="paper",
yref="paper"
),
dict(
x=-0.07,
y=0.5,
showarrow=False,
text=target_columns[1],
textangle=-90,
xref="paper",
yref="paper"
)
])
fig["layout"]["annotations"] = annotations
fig.show()
def correlation(dataset, subgroups, target_columns, translations, cols, group_size, include_dataset):
sets = [dataset] + subgroups[:group_size] if include_dataset else subgroups[:group_size]
titles = ['Dataset'] + [str(s.description) for s in subgroups[:group_size]] if include_dataset else \
[str(s.description) for s in subgroups[:group_size]]
fig = make_subplots(rows=math.ceil((group_size + 1) / cols), cols=cols,
subplot_titles=titles,
vertical_spacing=0.2)
for i, subgroup in enumerate(sets):
fig.add_trace(
go.Scatter(x=subgroup.data[target_columns[0]], y=subgroup.data[target_columns[1]], mode='markers'),
row=math.floor(i / cols) + 1, col=(i % cols) + 1
)
fig.add_trace(
go.Scatter(x=subgroup.data[target_columns[0]], y=(subgroup.data[target_columns[0]] * subgroup.target),
mode='lines'),
row=math.floor(i / cols) + 1, col=(i % cols) + 1
)
fig.update_xaxes(range=[dataset.data[target_columns[0]].min(), dataset.data[target_columns[0]].max()])
fig.update_yaxes(range=[dataset.data[target_columns[1]].min(), dataset.data[target_columns[1]].max()])
fig.update_layout(
showlegend=False
)
annotations = [a.to_plotly_json() for a in fig["layout"]["annotations"]]
annotations.extend([
dict(
x=0.5,
y=-0.15,
showarrow=False,
text=target_columns[0],
xref="paper",
yref="paper"
),
dict(
x=-0.07,
y=0.5,
showarrow=False,
text=target_columns[1],
textangle=-90,
xref="paper",
yref="paper"
)
])
fig["layout"]["annotations"] = annotations
fig.show()
def distribution(dataset, subgroups, target_columns, translations, cols, group_size, include_dataset):
sets = [dataset] + subgroups[:group_size] if include_dataset else subgroups[:group_size]
titles = ['Dataset'] + [str(s.description) for s in subgroups[:group_size]] if include_dataset else \
[str(s.description) for s in subgroups[:group_size]]
fig = make_subplots(rows=math.ceil((group_size + 1) / cols), cols=cols,
subplot_titles=titles,
vertical_spacing=0.3)
for i, subgroup in enumerate(sets):
X = [translations[target_columns[0]][x] for x in subgroup.target.index]
fig.add_trace(
go.Bar(x=X, y=subgroup.target.values),
row=math.floor(i / cols) + 1, col=(i % cols) + 1
)
# fig.update_yaxes(range=[0, dataset.target.values.max()])
fig.update_layout(
showlegend=False
)
annotations = [a.to_plotly_json() for a in fig["layout"]["annotations"]]
annotations.extend([
dict(
x=0.5,
y=-0.15,
showarrow=False,
text=target_columns[0],
xref="paper",
yref="paper"
),
dict(
x=-0.07,
y=0.5,
showarrow=False,
text='Frequency count',
textangle=-90,
xref="paper",
yref="paper"
)
])
fig["layout"]["annotations"] = annotations
fig.show()
visualizations = dict(
correlation=correlation,
distribution_cosine=distribution,
regression=correlation,
WRAcc=distribution,
heatmap=heatmap
)