From 91872f43020cb274508a838e9fe81da5a3403e44 Mon Sep 17 00:00:00 2001 From: Eric Schanet <eric.schanet@cern.ch> Date: Thu, 3 May 2018 16:45:08 +0200 Subject: [PATCH] Starting to mess with output scores plotting --- toolkit.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/toolkit.py b/toolkit.py index 2523105..e2d3bb4 100755 --- a/toolkit.py +++ b/toolkit.py @@ -404,7 +404,7 @@ class KerasROOTClassification(object): try: self.history = History() self.shuffle_training_data() - + self.model.fit(self.x_train, # the reshape might be unnescessary here self.y_train.reshape(-1, 1), @@ -541,7 +541,36 @@ class KerasROOTClassification(object): plt.clf() def plot_score(self): - pass + + logger.info("Plot output scores") + + sig_weights = np.empty(sum(self.y_test == 1)) + sig_weights.fill(self.class_weight[1]) + bkg_weights = np.empty(sum(self.y_test == 0)) + bkg_weights.fill(self.class_weight[0]) + + print sig_weights.reshape(-1,1).shape + print self.scores_test[self.y_test==1].shape + binning = [20,0,1] + + fig = plt.figure(figsize=(8,6)) + + ax1 = plt.subplot2grid((4,4), (0,0), colspan=4, rowspan=4) + ax1.tick_params(direction='in') + ax1.set_xlim((binning[1], binning[2])) + ax1.xaxis.set_ticks_position('both') + ax1.yaxis.set_ticks_position('both') + + s_histTest, s_binsTest, s_patchesTest = plt.hist(self.scores_test[self.y_test==1],weights=sig_weights.reshape(-1,1), histtype='stepfilled', color='r', label='Signal (Training)', alpha=0.5, bins=binning[0], range=(binning[1], binning[2])) + b_histTest, b_binsTest, b_patchesTest = plt.hist(self.scores_test[self.y_test==0],weights=bkg_weights.reshape(-1,1), histtype='stepfilled', color='b', label='Background (Training)', alpha=0.5, bins=binning[0], range=(binning[1], binning[2])) + + plt.xlabel('Output score') + plt.ylabel('a.u.') + + plt.legend(loc='upper right', framealpha=1.0) + plt.savefig(os.path.join(self.project_dir, "scores.pdf")) + plt.clf() + def plot_loss(self): -- GitLab