<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def average_precision_score(df, col_true=None, col_pred=None, col_scores=None, pos_label=1):
 """ Compute average precision score, i.e., the area under precision-recall curve. Note that this method will trigger the defined flow to execute. :param df: predicted data frame :type df: DataFrame :param pos_label: positive label :type pos_label: str :param col_true: true column :type col_true: str :param col_pred: predicted column, 'prediction_result' if absent. :type col_pred: str :param col_scores: score column, 'prediction_score' if absent. :type col_scores: str :return: Average precision score :rtype: float """

    if not col_pred:
        col_pred = get_field_name_by_role(df, FieldRole.PREDICTED_CLASS)
    if not col_scores:
        col_scores = get_field_name_by_role(df, FieldRole.PREDICTED_SCORE)
    thresh, tp, fn, tn, fp = _run_roc_node(df, pos_label, col_true, col_pred, col_scores)

    precisions = np.squeeze(np.asarray(tp * 1.0 / (tp + fp)))
    recalls = np.squeeze(np.asarray(tp * 1.0 / (tp + fn)))

    return np.trapz(precisions, recalls)