Floats not behaving like floats in a predefined function
<p>I am looking for the precision and recall of a spam filter using predefined functions</p>

<p>when using predefined functions, I cannot get them to return anything other than the value 1.0. </p>

<p>I know that this is not correct because I am supposed to get a precision result of 0.529411764706. </p>

<p>Also, I am using pop because for some reason the first entry of each list is not a number, so I can't use append(int(...</p>

<p>here are the functions:</p>

<pre><code>def precision(ref, hyp):
    """Calculates precision.
    Args:
    - ref: a list of 0's and 1's extracted from a reference file
    - hyp: a list of 0's and 1's extracted from a hypothesis file
    Returns:
    - A floating point number indicating the precision of the hypothesis
    """
    (n, np, ntp) = (len(ref), 0.0, 0.0)
    for i in range(n):
            if bool(hyp[i]):
                    np += 1
                    if bool(ref[i]):
                            ntp += 1
    return ntp/np

def recall(ref, hyp):
    """Calculates recall.
    Args:
    - ref: a list of 0's and 1's extracted from a reference file
    - hyp: a list of 0's and 1's extracted from a hypothesis file
    Returns:
    - A floating point number indicating the recall rate of the hypothesis
    """
    (n, nt, ntp) = (len(ref), 0.0, 0.0)
    for i in range(n):
            if bool(ref[i]):
                    nt += 1
                    if bool(hyp[i]):
                            ntp += 1
    return ntp/nt
</code></pre>

<p>Here's my code:</p>

<pre><code>import hw10_lib
from hw10_lib import precision
from hw10_lib import recall

actual = []
for line in open("/path/hw10.ref", 'r'):
    actual.append(line.strip().split('\t')[-1])
actual.pop(0)

predicted = []
for line in open("/path/hw10.hyp", 'r'):
    predicted.append(line.strip().split('\t')[-1])
predicted.pop(0)

prec = precision(actual, predicted)
rec = recall(actual, predicted)

print ('Precision: ', prec)
print ('Recall: ', rec)
</code></pre>
