healthcareai-py icon indicating copy to clipboard operation
healthcareai-py copied to clipboard

Utilities :: Validation Prediction Distribution Plots

Open Aylr opened this issue 7 years ago • 0 comments

Background

This is how we should be communicating validation output. Screen Shot 2018-01-29 at 8.25.13 PM.png

Working code from client work

def plot_distributions(df, actual_col, prediction_col, pos_label='Y', neg_label='N', bins=10, threshold=None):
    import seaborn as sns
    import matplotlib.pyplot as plt
    plt.xlim(0, 1)
    
    positives = df.loc[df[actual_col] == pos_label]
    negatives = df.loc[df[actual_col] == neg_label]

    ax = sns.distplot(positives[prediction_col], kde=False, label=pos_label, bins=bins, color='g')
    ax = sns.distplot(negatives[prediction_col], kde=False, label=neg_label, bins=bins, color='b')
    ax.set_title('Distributions of {} for {}'.format(prediction_col, actual_col))
    ax.legend()
    if threshold:
        plt.axvline(x=threshold, color='r')
    plt.show()

Aylr avatar Jan 30 '18 03:01 Aylr