Skip to content

Commit

Permalink
fix a bug in evaluating accuracy (#2736)
Browse files Browse the repository at this point in the history
* fix accuracy computation in MNIST siamese graph example

previous code:
```
def compute_accuracy(predictions, labels):
    '''Compute classification accuracy with a fixed threshold on distances.
    '''
    return labels[predictions.ravel() < 0.5].mean()
```
is not accuracy over all the samples, but over samples with negative prediction.

* add space around  "=="

follow François's suggestion
  • Loading branch information
llcao authored and fchollet committed Dec 19, 2016
1 parent 48d8853 commit fefb70b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion examples/mnist_siamese_graph.py
Expand Up @@ -75,7 +75,7 @@ def create_base_network(input_dim):
def compute_accuracy(predictions, labels):
'''Compute classification accuracy with a fixed threshold on distances.
'''
return labels[predictions.ravel() < 0.5].mean()
return np.mean(labels == (predictions.ravel() > 0.5))


# the data, shuffled and split between train and test sets
Expand Down

2 comments on commit fefb70b

@henry12231223
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
The accuracy however became very low after this update.
image
What's the problem? Thanks.

@fchollet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reverted this change.

Please sign in to comment.