<jupyter_start><jupyter_text>Sample notebooks for visualizing CNN classifier training and validation performance<jupyter_code># Imports
import math
import os
import sys
import pandas as pd
import numpy as np

import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm

# Add the path to the parent directory to augment search for module
par_dir = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
if par_dir not in sys.path:
    sys.path.append(par_dir)
    
# Import the custom plotting module
from plot_utils import plot_utils
import random

# Label dict - Dictionary mapping integer labels to str
label_dict = {0:"gamma", 1:"e", 2:"mu"}<jupyter_output><empty_output><jupyter_text>Change the `run_id` and `model_name` to plot the current model performanceRequires : The validation has to be run on the CNN classifier to generate the np_arrays ( `using tasks = train valid` ) in config. The `log_train.csv` must be present in the given directory.<jupyter_code># Using the absolute path
run_id = "20190621_203427"
model_name = "ConvNet"
dump_dir = "/home/akajal/WatChMaL/VAE/dumps/" + run_id + "/"
# Load the numpy arrays into memory
softmaxes = np.load(dump_dir + "softmax.npy")
labels = np.load(dump_dir + "labels.npy")
predictions = np.load(dump_dir + "predictions.npy")
energies = np.load(dump_dir + "energies.npy")

# Check the shapes of the loaded arrays
print("softmaxes shape : ", softmaxes.shape)
print("labels shape : ", labels.shape)
print("predictions shape : ", predictions.shape)
print("energies shape : ", energies.shape)

# Convert the energies from True to visible
plot_utils.convert_to_visible_energy(energies, labels)

# Plot the energy distribution
plot_utils.plot_event_energy_distribution(energies, labels, {"gamma":0, "e":1, "mu":2},
                                         show_plot=True)

# Plot the confusion matrix
plot_utils.plot_confusion_matrix(labels, predictions, energies, ["gamma", "e", "mu"],
                                 show_plot=True)

# Plot the classifier response curve
plot_utils.plot_classifier_response(softmaxes, labels, energies, 
                                    softmax_index_dict={"gamma":0, "e":1},
                                    event_dict={"e":1}, show_plot=True)

# Plot the ROC curve for e vs gamma
plot_utils.plot_ROC_curve_one_vs_one(softmaxes, labels, energies, {"gamma":0, "e":1},
                                     "e", "gamma", show_plot=True)
# Setup the path to the training log file
training_log = dump_dir + "log_train.csv"

# Plot using the downsample intervals
plot_utils.plot_training([training_log], [model_name], {model_name:["red", "blue"]},
                         downsample_interval=32, show_plot=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10213690691778342, 'fraction_numerical': 0.009779065555957986, 'mean_word_length': 3.932142857142857, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '548130', 'license': 'CNRI-Python', 'n_tokens_mistral': 870, 'n_tokens_neox': 841, 'n_words': 248, 'path': 'notebooks/notebooks_archive/June 20 - ConvNet Diagnostics.ipynb', 'repo_name': 'WatChMaL/CNN', 'size': '2761'}