Skip to content

Commit

Permalink
Merge commit '8eeac2779b13b339ef8318878ad02d3b445f2fbf'
Browse files Browse the repository at this point in the history
  • Loading branch information
xim committed Feb 28, 2012
2 parents 740e5eb + 8eeac27 commit e771691
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions nltk/metrics/scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
# For license information, see LICENSE.TXT


from itertools import izip
from math import fabs
import operator
from random import shuffle
from itertools import izip

try:
from scipy.stats.stats import betai
Expand All @@ -35,11 +36,7 @@ def accuracy(reference, test):
"""
if len(reference) != len(test):
raise ValueError("Lists must have the same length.")
num_correct = 0
for x, y in izip(reference, test):
if x == y:
num_correct += 1
return float(num_correct) / len(reference)
return float(sum(x == y for x, y in zip(reference, test))) / len(test)

def precision(reference, test):
"""
Expand Down Expand Up @@ -161,7 +158,7 @@ def approxrand(a, b, **kwargs):
shuffles = kwargs.get('shuffles', 999)
# there's no point in trying to shuffle beyond all possible permutations
shuffles = \
min(shuffles, reduce(lambda x, y: x * y, xrange(1, len(a) + len(b) + 1)))
min(shuffles, reduce(operator.mul, xrange(1, len(a) + len(b) + 1)))
stat = kwargs.get('statistic', lambda lst: float(sum(lst)) / len(lst))
verbose = kwargs.get('verbose', False)

Expand Down

0 comments on commit e771691

Please sign in to comment.