<jupyter_start><jupyter_text>Result Validation<jupyter_code>import numpy as np
import pandas as pd
import os
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
y_all_dgp = pd.read_hdf('./test-results/y_all-DGP', 'y_all')
# y_all_resnet = pd.read_hdf('./test-results/y_all-Resnet', 'y_all')
from sklearn.metrics import roc_curve
# Roc curve of each approach
def plot_roc_curve(y_all_list, labels):
    
    plt.figure(1)
    plt.plot([0, 1], [0, 1], 'k--')
    for i, y_all in enumerate(y_all_list):
        fpr, tpr, _ = roc_curve(y_all['y_true'].values, y_all['y_pred'].values)
        plt.plot(fpr, tpr, label=labels[i])
    plt.xlabel('False positive rate')
    plt.ylabel('True positive rate')
    plt.title('ROC curve')
    plt.legend(loc='best')
    plt.show()
plot_roc_curve(y_all_list=[y_all_dgp], labels=['DGP'])
target = target.cpu()
softmax, mixed_fs, samples = softmax.cpu(), mixed_fs.cpu(), samples.cpu()
softmax.shape
mixed_fs.shape
mixed_fs_transf = mixed_fs.t().view(batch_size, 100, num_classes)
mixed_fs_transf.shape
ax = sns.distplot(mixed_fs_transf[0,:,0])
ax.set_xlim([-10, 10])
plt.show()
sns.distplot(mixed_fs_transf[0,:,1])
plt.show()
np.exp(5)
np.abs(5.1/10)
samples.shape
sns.distplot(samples[0,0,:])
mixed_fs_transf[0,0,0]
mixed_fs_transf[0,0,1]
output.probs.shape
samples = samples.cpu().numpy()
import seaborn as sns
sns.distplot(mixed_fs[0,:].cpu())
samples_mixed_fs.t().shape
samples_mixed_fs.t().view(batch_size, 100, num_classes).shape
samples_mixed_fs_transformed = samples_mixed_fs.t().view(batch_size, 100, num_classes).cpu()
samples_mixed_fs_transformed.shape
samples_softmax = samples_softmax.cpu()
samples_mixed_fs_transformed[i,:,0].shape
ranges = []
correct = pred.cpu().eq(target.view_as(pred.cpu()))
for i in range(batch_size):
# for i in range(10):
    print('#########################################################')
    target_i = target[i]
    pred_i = output.probs[i,:].cpu().argmax()
    
    ranges.append(float(softmax[i,:,1].max()-softmax[i,:,1].min()))
    
    if target_i != pred_i:
        print(f'Actual Target: {target_i}')
        print(f'Class predicted: {pred_i}')
        
        plt.figure(figsize=(10,5))
        plt.subplot(121)
        class_ = 0
        sns.distplot(mixed_fs_transf[i,:,class_], bins=15, kde=False)
        mean = float(torch.mean(mixed_fs_transf[i,:,class_]))
        std = float(torch.std(mixed_fs_transf[i,:,class_]))
        print(f'Prediction == {class_}. Mean = {round(mean, 3)}. Std = {round(std, 3)}')
    #     plt.hist(samples_img[:, 0], bins=25)

        plt.subplot(122)
        class_ = 1
        sns.distplot(mixed_fs_transf[i,:,class_], bins=15, kde=False)
        mean = float(torch.mean(mixed_fs_transf[i,:,class_]))
        std = float(torch.std(mixed_fs_transf[i,:,class_]))
        print(f'Prediction == {class_}. Mean = {round(mean, 3)}. Std = {round(std, 3)}')
        plt.show()

    #     plt.figure(figsize=(10,5))
    #     sns.distplot(samples_mixed_fs_transformed[i,:,:].reshape(-1), bins=50)
    #     plt.show()
        print('\tSoftmax')
        plt.figure(figsize=(10,5))
        plt.subplot(121)
        class_ = 0 
        ax = sns.distplot(softmax[i,:,class_], bins=15, kde=False)
        mean = float(torch.mean(softmax[i,:,class_]))
        std = float(torch.std(softmax[i,:,class_]))
        print(f'Prediction == {class_}. Mean = {round(mean, 3)}. Std = {round(std, 3)}')
    #     ax.set_xlim([-0.05,1.05])
    #     plt.hist(samples_img[:, 0], bins=25)

        plt.subplot(122)
        class_ = 1
        ax = sns.distplot(softmax[i,:,class_], bins=15, kde=False)
        mean = float(torch.mean(softmax[i,:,class_]))
        std = float(torch.std(softmax[i,:,class_]))
        print(f'Prediction == {class_}. Mean = {round(mean, 3)}. Std = {round(std, 3)}')
    #     ax.set_xlim([-0.05,1.05])
        plt.show()
    
#     plt.figure(figsize=(10,5))
#     sns.distplot(samples_softmax[i,:,:].reshape(-1), bins=500, kde=False)
#     plt.show()

    
(samples_softmax[i,:,0] + samples_softmax[i,:,1]).sum()
samples_softmax[i,:100,1]
correct = correct.numpy()
import pandas as pd
df_ranges = pd.DataFrame({'correct': list(correct),
                         'ranges': ranges})
df_ranges.head()
sns.boxplot(x='correct', y='ranges', data=df_ranges, whis=1)
plot_hist(img_samples=samples_mixed_fs.transpose)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18982432124115903, 'fraction_numerical': 0.026694045174537988, 'mean_word_length': 3.892857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '99753', 'license': 'MIT', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1724, 'n_words': 259, 'path': 'notebooks/final-results.ipynb', 'repo_name': 'AlbertoCastelo/bayesian-dl-medical-diagnosis', 'size': '4383'}