1

Im trying to find the Precision and Recall of these two sentence but getting following error what am I doing wrong?

Code:

from nltk.metrics import precision, recall
from sklearn.metrics import precision_score
import sklearn.metrics
from sklearn import metrics
from sys import argv
from time import time
import numpy
import csv
import nltk,math
import numpy as np


set1 = "The horse raced past the barn fell" 
set2 = "The horse that was raced past the barn fell"
length = np.amin([len(set1),len(set2)])
set1 = set1[:length]
set2 = set2[:length]

K =  sklearn.metrics.precision_score(set1,set2,average=None)

print k

Error:

ValueError: Expected array-like (array or non-string sequence), got 'The horse raced past the barn fell'
JKLM
  • 1,470
  • 3
  • 28
  • 66
  • 1
    No, if you are trying to compare the expected output vs actual of a _text generator_, this isn't the way to do it. You'll want something more along the lines of edit distance or fuzzy matching. – cs95 Oct 23 '17 at 23:50
  • 1
    I'd recommend taking a look at the `fuzzywuzzy` module. – cs95 Oct 23 '17 at 23:51
  • how do I calculate precision with fuzzywuzzy its a string matching function – JKLM Oct 23 '17 at 23:57
  • 1
    https://stackoverflow.com/questions/31806695/when-to-use-which-fuzz-function-to-compare-2-strings – cs95 Oct 23 '17 at 23:59
  • Possible duplicate of [When to use which fuzz function to compare 2 strings](https://stackoverflow.com/questions/31806695/when-to-use-which-fuzz-function-to-compare-2-strings) – ivan_pozdeev Oct 24 '17 at 00:01

0 Answers0