

def f_measure(reference, test, alpha=0.5):
    '\n    Given a set of reference values and a set of test values, return\n    the f-measure of the test values, when compared against the\n    reference values.  The f-measure is the harmonic mean of the\n    ``precision`` and ``recall``, weighted by ``alpha``.  In particular,\n    given the precision *p* and recall *r* defined by:\n\n    - *p* = card(``reference`` intersection ``test``)/card(``test``)\n    - *r* = card(``reference`` intersection ``test``)/card(``reference``)\n\n    The f-measure is:\n\n    - *1/(alpha/p + (1-alpha)/r)*\n\n    If either ``reference`` or ``test`` is empty, then ``f_measure``\n    returns None.\n\n    :type reference: set\n    :param reference: A set of reference values.\n    :type test: set\n    :param test: A set of values to compare against the reference set.\n    :rtype: float or None\n    '
    p = precision(reference, test)
    r = recall(reference, test)
    if ((p is None) or (r is None)):
        return None
    if ((p == 0) or (r == 0)):
        return 0
    return (1.0 / ((alpha / p) + ((1 - alpha) / r)))

dataset/ETHPy150Open nltk/nltk/nltk/metrics/scores.py f_measure/original