Source code for contextualized.analysis.accuracy_split

"""
Utilities for post-hoc analysis of trained Contextualized models.
"""

from typing import *

import numpy as np
import pandas as pd
from sklearn.metrics import roc_auc_score as roc


def get_roc(Y_true: np.ndarray, Y_pred: np.ndarray) -> float:
    """Measures ROC. Return np.nan if no valid ROC value."""
    try:
        return roc(Y_true, Y_pred)
    except (IndexError, ValueError):
        return np.nan