def fscore(rec, prec, beta=1.0):
    """Computes the F_{beta}-score of given precision and recall values."""
    if (rec == 0 and prec == 0) or prec < 0 or rec < 0:
        return 0.0
    return (1.0 + beta) * (prec * rec / (beta**2 * prec + rec))