我不明白为什么第一个示例无效,而第二个示例无效。它们是相同的代码,因此很高兴知道为什么它无法正常工作以寻求帮助。
def naive_bayes_eval(test_sms_file,f):
Precision=1
est_spam =0
pas_spam =0
nbr_spam =0
for ligne in open(test_sms_file,'r').readlines():
if("spam" in ligne):
nbr_spam = nbr_spam + 1
if f(ligne.replace('spam',''))== 1:
est_spam=est_spam+1
if("ham" in ligne):
if( f(ligne.replace('ham',''))== 1):
pas_spam = pas_spam+1
recall = est_spam/nbr_spam;
if (est_spam + pas_spam)>0:
Precision = est_spam/(est_spam + pas_spam)
return(recall,Precision)
def naive_bayes_eval(test_sms_file,f):
Precision=1
est_spam =0
pas_spam =0
nbr_spam =0
f=open(test_sms_file,'r')
lines=f.readlines()
for ligne in lines:
if("spam" in ligne):
nbr_spam = nbr_spam + 1
if f(ligne.replace('spam',Precision)