def f_score(Theta_true, Theta_est, beta=1, eps=1e-6, per_ts=False):
"""Compute f1 score in the same manner as `precision` and `recall`.
Therefore see those two functions for the respective waiting and per_ts
explanation.
Parameters
----------
Theta_true : 3D ndarray, shape (timesteps, n_vertices, n_vertices)
Theta_est : 3D ndarray, shape (timesteps, n_vertices, n_vertices)
beta : float (default 1)
beta value of the F score to be computed
eps : float
per_ts : bool
whether to compute average or per timestep recall
Returns
-------
ndarray or float
recall list or single precision value
"""
prec = precision(Theta_true, Theta_est, eps, per_ts=True)
rec = recall(Theta_true, Theta_est, eps, per_ts=True)
with np.errstate(divide='ignore', invalid='ignore'):
nom = (1 + beta**2) * prec * rec
print(beta**2 * prec)
den = beta**2 * prec + rec
f = np.nan_to_num(np.true_divide(nom, den))
return f if per_ts else np.sum(f) / len(Theta_true)
评论列表
文章目录