<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fbeta_score(df, col_true=None, col_pred='precision_result', beta=1.0, pos_label=1, average=None):
 r""" Compute f-beta score of a predicted DataFrame. f-beta is defined as .. math:: \frac{1 + \beta^2 \cdot precision \cdot recall}{\beta^2 \cdot precision + recall} F-beta score is a generalization of f-1 score. :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-beta of every class is given as a list. * When ``average`` == 'binary', f-beta of class specified in ``pos_label`` is given. * When ``average`` == 'micro', f-beta of overall precision and recall is given, where overall precision and recall are computed in micro-average mode. * When ``average`` == 'macro', average f-beta of all the class is given. * When ``average`` == `weighted`, average f-beta 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 array([ 0. , 0.33333333, 0.5 ]) 0.27 0.33 0.33 """

    if not col_pred:
        col_pred = get_field_name_by_role(df, FieldRole.PREDICTED_CLASS)
    mat, label_list = _run_cm_node(df, col_true, col_pred)
    class_dict = dict((label, idx) for idx, label in enumerate(label_list))
    tps = np.diag(mat)
    pred_count = np.sum(mat, axis=0)
    supp_count = np.sum(mat, axis=1)
    beta2 = beta ** 2

    precision = tps * 1.0 / pred_count
    recall = tps * 1.0 / supp_count
    ppr = precision * beta2 + recall
    ppr[ppr == 0] = 1e-6

    fbeta = (1 + beta2) * precision * recall / ppr

    if average is None:
        return fbeta
    elif average == 'binary':
        class_idx = class_dict[pos_label]
        return fbeta[class_idx]
    elif average == 'micro':
        g_precision = np.sum(tps) * 1.0 / np.sum(supp_count)
        g_recall = np.sum(tps) * 1.0 / np.sum(pred_count)
        return (1 + beta2) * g_precision * g_recall / (beta2 * g_precision + g_recall)
    elif average == 'macro':
        return np.mean(fbeta)
    elif average == 'weighted':
        return sum(fbeta * supp_count) / sum(supp_count)