def confusionMatrix(predicted, actual, threshold):
    """
    计算数据的混淆矩阵表数值

    :param predicted: 实验数据集
    :param actual: 真实数据集
    :param threshold: 阀值
    :return: 数值形式[tp, fn, tp, tn, rate]
    """
    # 检查数据长度，避免无效输入
    if len(predicted) != len(actual):
        return -1

    # 定义混淆矩阵的四项指标
    tp = 0.0  # 真实例
    fp = 0.0  # 假实例
    tn = 0.0  # 真负例
    fn = 0.0  # 假负率

    for i in range(len(actual)):
        if actual[i] > 0.5:
            if predicted[i] > threshold:
                tp += 1.0
            else:
                fn += 1.0
        else:
            if predicted[i] < threshold:
                tn += 1.0
            else:
                fp += 1.0
    # 误分率
    rate =(fn + fp) / (tp + fn + tn + fp)
    rtn = [tp, fn, fp, tn, rate]
    return rtn