Я не понимаю, почему первый пример не работает, а второй работает. Это один и тот же код, и хорошо знать, почему он не работает. Спасибо за помощь.
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',''))== 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)