def f1_score(df, col_true=None, col_pred='precision_result', pos_label=1, average=None):
    r"""
    Compute f-1 score of a predicted DataFrame. f-1 is defined as

    .. math::

        \frac{2 \cdot precision \cdot recall}{precision + recall}


    :Parameters:
        - **df** - predicted data frame
        - **col_true** - column name of true label
        - **col_pred** - column name of predicted label, 'prediction_result' by default.
        - **pos_label** - denote the desired class label when ``average`` == `binary`
        - **average** - denote the method to compute average.
    :Returns:
        Recall score
    :Return type:
        float | numpy.array[float]

    The parameter ``average`` controls the behavior of the function.

    * When ``average`` == None (by default), f-1 of every class is given as a list.

    * When ``average`` == 'binary', f-1 of class specified in ``pos_label`` is given.

    * When ``average`` == 'micro', f-1 of overall precision and recall is given, where overall precision and recall are computed in micro-average mode.

    * When ``average`` == 'macro', average f-1 of all the class is given.

    * When ``average`` == `weighted`, average f-1 of all the class weighted by support of every true classes is given.


    :Example:

    Assume we have a table named 'predicted' as follows:

    ======== ===================
    label    prediction_result
    ======== ===================
    0        1
    1        2
    2        1
    1        1
    1        0
    2        2
    ======== ===================

    Different options of ``average`` parameter outputs different values:

.. code-block:: python

    >>> f1_score(predicted, 'label', average=None)
    array([ 0.        ,  0.33333333,  0.5       ])
    >>> f1_score(predicted, 'label', average='macro')
    0.27
    >>> f1_score(predicted, 'label', average='micro')
    0.33
    >>> f1_score(predicted, 'label', average='weighted')
    0.33
    """
    if not col_pred:
        col_pred = get_field_name_by_role(df, FieldRole.PREDICTED_CLASS)
    return fbeta_score(df, col_true, col_pred, pos_label=pos_label, average=average)
def f1_score ( df , col_true = None , col_pred = 'precision_result' , pos_label = 1 , average = None ) : if not col_pred : col_pred = get_field_name_by_role ( df , FieldRole . PREDICTED_CLASS ) return fbeta_score ( df , col_true , col_pred , pos_label = pos_label , average = average )
r"""
    Compute f-1 score of a predicted DataFrame. f-1 is defined as

    .. math::

        \frac{2 \cdot precision \cdot recall}{precision + recall}


    :Parameters:
        - **df** - predicted data frame
        - **col_true** - column name of true label
        - **col_pred** - column name of predicted label, 'prediction_result' by default.
        - **pos_label** - denote the desired class label when ``average`` == `binary`
        - **average** - denote the method to compute average.
    :Returns:
        Recall score
    :Return type:
        float | numpy.array[float]

    The parameter ``average`` controls the behavior of the function.

    * When ``average`` == None (by default), f-1 of every class is given as a list.

    * When ``average`` == 'binary', f-1 of class specified in ``pos_label`` is given.

    * When ``average`` == 'micro', f-1 of overall precision and recall is given, where overall precision and recall are computed in micro-average mode.

    * When ``average`` == 'macro', average f-1 of all the class is given.

    * When ``average`` == `weighted`, average f-1 of all the class weighted by support of every true classes is given.


    :Example:

    Assume we have a table named 'predicted' as follows:

    ======== ===================
    label    prediction_result
    ======== ===================
    0        1
    1        2
    2        1
    1        1
    1        0
    2        2
    ======== ===================

    Different options of ``average`` parameter outputs different values:

.. code-block:: python

    >>> f1_score(predicted, 'label', average=None)
    array([ 0.        ,  0.33333333,  0.5       ])
    >>> f1_score(predicted, 'label', average='macro')
    0.27
    >>> f1_score(predicted, 'label', average='micro')
    0.33
    >>> f1_score(predicted, 'label', average='weighted')
    0.33