def dump_cycle(f, user, ps, symptom, cl):
""" Takes predicted values, dumps appropriate results accordingly.
:param f: output file
:param user: user id
:param ps: predictions for this user
:param symptom: symptom for which these predictions are for
:param cl: expected cycle length
"""
y = ps
y[np.isnan(y)] = 0
x = np.array(list(range(len(ps))))
xx = np.linspace(x.min(), x.max(), cl)
itp = interp1d(x, y, kind='linear')
window_size, poly_order = 5, 3
yy_sg = savgol_filter(itp(xx), window_size, poly_order)
for i in range(int(cl)):
lp = np.max([.001, np.min([yy_sg[int(i)], .99])])
f.write("%s,%d,%s,%g\n" % (user, i, symptom, lp))
评论列表
文章目录