(y_test, y_score, interpreter=None)
return img
plotting function that generates roc curves for data given to it.

    :param y_test: is the testing data used
    :param y_score: is the score when the testing data was called
    :param interpreter: is what was used to preprocess
    :return a roc plot
plotting function that generates roc curves for data given to it.
plotting function that generates roc curves for data given to it .
def plot_mc_roc(y_test, y_score, interpreter=None):
    '''
    plotting function that generates roc curves for data given to it.

    :param y_test: is the testing data used
    :param y_score: is the score when the testing data was called
    :param interpreter: is what was used to preprocess
    :return a roc plot
    '''
    lw = 2
    n_classes = len(np.unique(y_test))
    classes = pd.unique(y_test)
    label_binarizer = LabelBinarizer()
    label_binarizer.fit(np.concatenate((y_test, y_score)))
    if n_classes != 2:
        y_test = label_binarizer.transform(y_test)
        y_score = label_binarizer.transform(y_score)
    else:
        n_classes = 1
        y_test = y_test.reshape(-1, 1)
        y_score = y_score.reshape(-1, 1)

    # Compute ROC curve and ROC area for each class
    fpr = dict()
    tpr = dict()
    roc_auc = dict()
    for i in range(n_classes):
        fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])
        roc_auc[i] = auc(fpr[i], tpr[i])

    # Compute micro-average ROC curve and ROC area
    fpr["micro"], tpr["micro"], _ = roc_curve(y_test.ravel(), y_score.ravel())
    roc_auc["micro"] = auc(fpr["micro"], tpr["micro"])
    # First aggregate all false positive rates
    all_fpr = np.unique(np.concatenate([fpr[i] for i in range(n_classes)]))

    # Then interpolate all ROC curves at this points
    mean_tpr = np.zeros_like(all_fpr)
    for i in range(n_classes):
        mean_tpr += interp(all_fpr, fpr[i], tpr[i])

    # Finally average it and compute AUC
    mean_tpr /= n_classes

    fpr["macro"] = all_fpr
    tpr["macro"] = mean_tpr
    roc_auc["macro"] = sklearn.metrics.auc(fpr["macro"], tpr["macro"])

    # Plot all ROC curves
    img = plt.figure()
    plt.plot(fpr["micro"], tpr["micro"],
             label='micro-average ROC curve (area = {0:0.2f})'
                   ''.format(roc_auc["micro"]),
             color='deeppink', linestyle=':', linewidth=4)

    plt.plot(fpr["macro"], tpr["macro"],
             label='macro-average ROC curve (area = {0:0.2f})'
                   ''.format(roc_auc["macro"]),
             color='navy', linestyle=':', linewidth=4)

    for i in range(n_classes):
        plt.plot(
            fpr[i],
            tpr[i],
            lw=lw,
            label='ROC curve of class {0} (area = {1:0.2f})'
                ''.format(
                interpreter.inverse_transform(
                [[label_binarizer.classes_[i]]])[0],
                roc_auc[i]))

    plt.plot([0, 1], [0, 1], 'k--', lw=lw)
    plt.xlim([0.0, 1.0])
    plt.ylim([0.0, 1.05])
    plt.xlabel('False Positive Rate')
    plt.ylabel('True Positive Rate')
    plt.title('ROC Curves')
    plt.legend(loc="lower right")
    return img
def plot_mc_roc ( y_test , y_score , interpreter = None ) : lw = 2 n_classes = len ( np . unique ( y_test ) ) classes = pd . unique ( y_test ) label_binarizer = LabelBinarizer ( ) label_binarizer . fit ( np . concatenate ( ( y_test , y_score ) ) ) if n_classes != 2 : y_test = label_binarizer . transform ( y_test ) y_score = label_binarizer . transform ( y_score ) else : n_classes = 1 y_test = y_test . reshape ( - 1 , 1 ) y_score = y_score . reshape ( - 1 , 1 ) # Compute ROC curve and ROC area for each class fpr = dict ( ) tpr = dict ( ) roc_auc = dict ( ) for i in range ( n_classes ) : fpr [ i ] , tpr [ i ] , _ = roc_curve ( y_test [ : , i ] , y_score [ : , i ] ) roc_auc [ i ] = auc ( fpr [ i ] , tpr [ i ] ) # Compute micro-average ROC curve and ROC area fpr [ "micro" ] , tpr [ "micro" ] , _ = roc_curve ( y_test . ravel ( ) , y_score . ravel ( ) ) roc_auc [ "micro" ] = auc ( fpr [ "micro" ] , tpr [ "micro" ] ) # First aggregate all false positive rates all_fpr = np . unique ( np . concatenate ( [ fpr [ i ] for i in range ( n_classes ) ] ) ) # Then interpolate all ROC curves at this points mean_tpr = np . zeros_like ( all_fpr ) for i in range ( n_classes ) : mean_tpr += interp ( all_fpr , fpr [ i ] , tpr [ i ] ) # Finally average it and compute AUC mean_tpr /= n_classes fpr [ "macro" ] = all_fpr tpr [ "macro" ] = mean_tpr roc_auc [ "macro" ] = sklearn . metrics . auc ( fpr [ "macro" ] , tpr [ "macro" ] ) # Plot all ROC curves img = plt . figure ( ) plt . plot ( fpr [ "micro" ] , tpr [ "micro" ] , label = 'micro-average ROC curve (area = {0:0.2f})' '' . format ( roc_auc [ "micro" ] ) , color = 'deeppink' , linestyle = ':' , linewidth = 4 ) plt . plot ( fpr [ "macro" ] , tpr [ "macro" ] , label = 'macro-average ROC curve (area = {0:0.2f})' '' . format ( roc_auc [ "macro" ] ) , color = 'navy' , linestyle = ':' , linewidth = 4 ) for i in range ( n_classes ) : plt . plot ( fpr [ i ] , tpr [ i ] , lw = lw , label = 'ROC curve of class {0} (area = {1:0.2f})' '' . format ( interpreter . inverse_transform ( [ [ label_binarizer . classes_ [ i ] ] ] ) [ 0 ] , roc_auc [ i ] ) ) plt . plot ( [ 0 , 1 ] , [ 0 , 1 ] , 'k--' , lw = lw ) plt . xlim ( [ 0.0 , 1.0 ] ) plt . ylim ( [ 0.0 , 1.05 ] ) plt . xlabel ( 'False Positive Rate' ) plt . ylabel ( 'True Positive Rate' ) plt . title ( 'ROC Curves' ) plt . legend ( loc = "lower right" ) return img