Skip to content

Commit

Permalink
Fixed confusion matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragav Venkatesan committed Mar 11, 2017
1 parent 9806a9a commit 7245bb5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions yann/modules/resultor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ def _store_confusion_img (self, confusion, filename, verbose = 2):
"""
if verbose >= 3:
print ("... Saving the file down")
confusion = confusion / confusion.max()
confusion = confusion / confusion.sum(axis = 0)
fig = plt.figure()
plt.matshow(confusion)
plt.title('Confusion matrix')
plt.set_cmap('Greens')
plt.set_cmap('GnBu')
plt.colorbar()
plt.ylabel('True labels')
plt.xlabel('Predicated labels')
plt.xlabel('Predicted labels')
plt.savefig(filename)
plt.close('all')
14 changes: 8 additions & 6 deletions yann/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1935,13 +1935,15 @@ def _initialize_confusion (self, classifier = None, verbose = 2):
print("... initializing confusion matrix function")

_classes = T.scalar('num_classes')
_predictions = self.inference_layers[classifier].predictions
_labels = self.y
_predictions = self.inference_layers[classifier].predictions.dimshuffle(0, 'x')
_labels = self.y.dimshuffle(0, 'x')
_order = T.arange(self.num_classes_to_classify)

oneHot_labels = T.eq(_labels, _order).astype('int32')
oneHot_predictions = T.eq(_predictions, _order).astype('int32')

confusion = T.dot( T.eq( _predictions.dimshuffle(0, 'x'), \
T.arange(self.num_classes_to_classify).astype('int32')).T, \
T.eq( _labels.dimshuffle(0,'x'), \
T.arange(self.num_classes_to_classify).astype('int32')))
confusion = T.dot(oneHot_labels.T, oneHot_predictions)
# confusion_normalized = confusion / confusion.sum(axis = 0)

index = T.lscalar('index')
self.mini_batch_confusion = theano.function(
Expand Down

0 comments on commit 7245bb5

Please sign in to comment.