-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
64 lines (48 loc) · 1.84 KB
/
utils.py
File metadata and controls
64 lines (48 loc) · 1.84 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
import pandas as pd
from sbgresults import SbgResults
import bokeh.plotting as bk
from bokeh.embed import components
from bokeh.models.tools import HoverTool
import numpy as np
from scipy.stats import beta
from collections import OrderedDict
COLORS = ["#7fc97f", "#beaed4", "#fdc086", "#ffff99", "#386cb0", "#f0027f", "#bf5b17"]
LINE_WIDTH = 3
MARKER_SIZE = 10
def parse(data_url, periods, discount, value):
ds = pd.read_csv(data_url)
ds.reindex(index=ds['t'])
del ds['t']
return [SbgResults(c, dict(zip(ds[c].index, ds[c])), periods, discount, value) for c in ds]
def _mult100(xs):
return [100*x for x in xs]
def plot_sbg_results(sbg_results):
p = bk.figure(title="Actual and Predicted Survival", tools="hover,")
p.axis[1].axis_label = "%"
hover = p.select(dict(type=HoverTool))
#hover.always_active = True
#hover.snap_to_data = True
hover.tooltips = OrderedDict([
("Period", "@x"),
("Survive %", "@y"),
])
for i, result in enumerate(sbg_results):
p.line(range(len(result.predicted)),
_mult100(result.predicted),
color=COLORS[i],
legend=result.name,
line_width=LINE_WIDTH)
p.scatter(range(len(result.actual)),
_mult100(result.actual),
color=COLORS[i],
legend=result.name,
marker='o',
size=MARKER_SIZE)
return components(p)
def plot_sbg_retention_distribution(sbg_results):
p = bk.figure(title="Distribution of Retention Probability", y_range=[0, 6], tools="")
theta = np.linspace(.001, .999, num=1000)
for i, result in enumerate(sbg_results):
pdf = beta.pdf(theta, a=result.alpha, b=result.beta)
p.line(theta, pdf, color=COLORS[i], legend=result.name, line_width=LINE_WIDTH)
return components(p)