def get_metric_text(protected_attr, target_value, metric_name, bias_type=
    'dataset'):
    """
    Return a text value for a specific metric

    Parameters
    ----------
    protected_attr:
        Protected attribute to inspect
    target_value: str
        Specific value of the target  
    metric_name: str
        Metric's name 
    bias_type: str (default: 'dataset')
        Bias type (can only be 'dataset' or 'model')

    Returns
    -------
    str
        String of the metric calculus

    Raises
    ------
    ValueError:
        `bias_type` parameter has to be 'dataset' or 'model'
    """
    if bias_type not in ['dataset', 'model']:
        raise ValueError("bias_type has to be 'dataset' or 'model'")
    metrics = protected_attr.metrics
    value = metrics.loc[target_value, metric_name]
    if bias_type == 'dataset':
        freq_unpr = protected_attr.get_freq(target_value, privileged=False)
        freq_priv = protected_attr.get_freq(target_value, privileged=True)
        if metric_name == 'Disparate impact':
            formula = (
                '$\\frac{Pr(Y = %s\\ |\\ D = unprivileged)}{Pr(Y = %s\\ |\\ D = privileged)}$'
                 % (target_value, target_value))
            return formula + '\n' + '$ = \\frac{%.2f}{%.2f}$ = %.2f' % (
                freq_unpr, freq_priv, value)
        elif metric_name == 'Statistical parity difference':
            formula = (
                '$Pr(Y = %s\\ |\\ _{D = unprivileged}) - Pr(Y = %s\\ |\\ _{D = privileged})$'
                 % (target_value, target_value))
            return formula + '\n' + '= %.2f - %.2f = %.2f' % (freq_unpr,
                freq_priv, value)
    elif bias_type == 'model':
        freq_unpr = protected_attr.get_freq(target_value, privileged=False,
            predictions=True)
        freq_priv = protected_attr.get_freq(target_value, privileged=True,
            predictions=True)
        if metric_name == 'Disparate impact':
            formula = (
                '$\\frac{Pr(\\hat{Y} = %s\\ |\\ D = unprivileged)}{Pr(\\hat{Y} = %s\\ |\\ D = privileged)}$'
                 % (target_value, target_value))
            return formula + '\n' + '$ = \\frac{%.2f}{%.2f}$ = %.2f' % (
                freq_unpr, freq_priv, value)
        elif metric_name == 'Statistical parity difference':
            formula = (
                '$Pr(\\hat{Y} = %s\\ |\\ _{D = unprivileged}) - Pr(\\hat{Y} = %s\\ |\\ _{D = privileged})$'
                 % (target_value, target_value))
            return formula + '\n' + '= %.2f - %.2f = %.2f' % (freq_unpr,
                freq_priv, value)
        elif metric_name == 'Equal opportunity difference':
            TPR_unpriv = protected_attr.true_positive_rate(target_value,
                privileged=False)
            TPR_priv = protected_attr.true_positive_rate(target_value,
                privileged=True)
            formula = '$TPR_{unprivileged} - TPR_{privileged}$'
            return formula + '\n = %.2f - %.2f = %.2f' % (TPR_unpriv,
                TPR_priv, value)
        elif metric_name == 'Average abs odds difference':
            TPR_unpriv = protected_attr.true_positive_rate(target_value,
                privileged=False)
            TPR_priv = protected_attr.true_positive_rate(target_value,
                privileged=True)
            FPR_unpriv = protected_attr.false_positive_rate(target_value,
                privileged=False)
            FPR_priv = protected_attr.false_positive_rate(target_value,
                privileged=True)
            formula = (
                '$\\frac{1}{2}\\left[|FPR_{unprivileged} - FPR_{privileged}| + |TPR_{unprivileged} - TPR_{privileged}|\\right]$'
                )
            return (formula + '\n' + 
                '= $\\frac{1}{2}\\left[|%.2f - %.2f| + |%.2f - %.2f|\\right]$ = %.2f'
                 % (FPR_unpriv, FPR_priv, TPR_unpriv, TPR_priv, value))
        elif metric_name == 'Theil index':
            formula = (
                '$\\frac{1}{n}\\sum_{i=1}^n\\frac{b_{i}}{\\mu}\\ln\\frac{b_{i}}{\\mu}$'
                )
            return formula + ' = %.2f' % value
    return 'no metric selected'
