-
Notifications
You must be signed in to change notification settings - Fork 3
/
visuals.py
155 lines (124 loc) · 3.44 KB
/
visuals.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
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
151
152
153
154
155
import numpy as np
import plotly.graph_objs as go
import plotly.offline as offline_py
offline_py.init_notebook_mode(connected=True)
def plot_interactions(articles_by_user):
trace0 = go.Histogram(
x = articles_by_user,
xbins = {
"start": np.min(articles_by_user),
"end": np.max(articles_by_user),
"size": 1
}
)
data = [trace0]
layout = go.Layout(
title = "DISTRIBUTION OF HOW MANY ARTICLES <br> A USER INTERACTS WITH ",
xaxis = {
"title": "Number of articles",
"automargin": True,
"showgrid": True,
"tick0": 0,
"dtick": 25,
"zeroline": False
},
yaxis = {
"title": "Number of users",
"automargin": True,
"showgrid": True,
}
)
fig = go.Figure(data = data, layout = layout)
offline_py.iplot(fig)
def plot_accuracy_train(train_errs_cum, num_latent_feats, df):
trace0 = go.Scatter(
x = num_latent_feats,
y = 1 - np.array(train_errs_cum)/df.shape[0]
)
data = [trace0]
layout = go.Layout(
title = "Accuracy vs # of Features <br> for Training Data",
xaxis = {
"title": "# of Features",
"automargin": True
},
yaxis = {
"title": "Accuracy",
"automargin": True
}
)
fig = go.Figure(data = data, layout = layout)
offline_py.iplot(fig)
def plot_accuracy_test(test_errs_cum, num_latent_feats, df):
trace0 = go.Scatter(
x = num_latent_feats,
y = 1 - np.array(test_errs_cum)/df.shape[0]
)
data = [trace0]
layout = go.Layout(
title = "Accuracy vs # of Features <br> for Test Data",
xaxis = {
"title": "# of Features",
"automargin": True
},
yaxis = {
"title": "Accuracy",
"automargin": True
}
)
fig = go.Figure(data = data, layout = layout)
offline_py.iplot(fig)
def plot_f1_train(train_f1, num_latent_feats):
trace0 = go.Scatter(
x = num_latent_feats,
y = train_f1
)
data = [trace0]
layout = go.Layout(
title = "F1 Score vs # of Features <br> for Training Data",
xaxis = {
"title": "# of Features",
"automargin": True
},
yaxis = {
"title": "F1 Score",
"automargin": True
}
)
fig = go.Figure(data = data, layout = layout)
offline_py.iplot(fig)
def plot_f1_test(test_f1, num_latent_feats):
trace0 = go.Scatter(
x = num_latent_feats,
y = test_f1
)
data = [trace0]
layout = go.Layout(
title = "F1 Score vs # of Features <br> for Test Data",
xaxis = {
"title": "# of Features",
"automargin": True,
"tick0": 0,
"dtick": 50
},
yaxis = {
"title": "F1 Score",
"automargin": True
},
# vertical line at x=100
shapes = [
{
"type": "line",
"x0": 150,
"y0": 0,
"x1": 150,
"y1": 0.08598726,
"line": {
"color": "rgb(50, 171, 96)",
"width": 2
}
}
]
)
fig = go.Figure(data = data, layout = layout)
offline_py.iplot(fig)