本文整理匯總了Python中reverend.thomas.Bayes.untrain方法的典型用法代碼示例。如果您正苦於以下問題:Python Bayes.untrain方法的具體用法?Python Bayes.untrain怎麽用?Python Bayes.untrain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類reverend.thomas.Bayes
的用法示例。
在下文中一共展示了Bayes.untrain方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: untrained
# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import untrain [as 別名]
def untrained(self, cr, uid, ids, context=None):
for id in ids:
record = self.read(cr, uid, id, ['category_id','description'])
if record['description']:
group_obj = self.pool.get('crm.bayes.group')
cat_obj = self.pool.get('crm.bayes.categories')
cat_rec = cat_obj.read(cr, uid, record['category_id'][0],[])
guesser = Bayes()
data = ""
for rec in group_obj.browse(cr, uid, [cat_rec['group_id'][0]]):
if rec['train_data']:
data += rec['train_data']
if data :
myfile = file(file_path+"crm_bayes.bay", 'w')
myfile.write(data)
myfile.close()
guesser.load(file_path+"crm_bayes.bay")
guesser.untrain(cat_rec['name'],record['description'])
guesser.save(file_path+"crm_bayes.bay")
myfile = file(file_path+"crm_bayes.bay", 'r')
data= ""
for fi in myfile.readlines():
data += fi
group_obj.write(cr, uid, cat_rec['group_id'][0], {'train_data': data})
cat_obj.write(cr, uid, record['category_id'][0], {'train_messages':int(cat_rec['train_messages']) - 1 })
cr.execute("select sum(train_messages) as tot_train,sum(guess_messages) as tot_guess from crm_bayes_categories where group_id=%d"% cat_rec['group_id'][0])
rec = cr.dictfetchall()
if rec[0]['tot_guess']:
percantage = float(rec[0]['tot_guess'] *100) / float(rec[0]['tot_guess'] + rec[0]['tot_train'])
else :
percantage = 0.0
group_obj.write(cr, uid, cat_rec['group_id'][0], {'train_data': data,'automate_test':percantage})
self.write(cr, uid, id, {'state_bayes':'untrained'})
return True
示例2: mark
# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import untrain [as 別名]
def mark(request, flag):
id = request.GET.get('post', None)
feed = request.GET.get('feed', None)
category = request.GET.get('category')
tag = request.GET.get('tag') or None
try:
if feed:
posts = Post.objects.filter(feed=feed)
else:
posts = Post.objects.filter(id=id)
except Post.DoesNotExist:
return HttpResponseRedirect('/')
bayes = Brain.objects.get(user=request.user) #login required
brain = Bayes()
brain.loads(base64.decodestring(bayes.data))
if flag in ('read', 'unread'):
flag = flag == 'read'
posts.update(read=flag)
else:
for post in posts:
text = "%s %s %s" % (post.title, post.author, post.summary)
t1 = Tag.objects.get(id=flag)
if t1 in post.tags.all() and not feed:
post.tags.remove(t1)
brain.untrain(t1.name, text)
else:
post.tags.add(t1)
brain.train(t1.name, text)
post.save()
bayes.data = base64.encodestring(brain.saves())
bayes.save()
if category:
return HttpResponseRedirect('/?category=%s' % category)
elif feed:
return HttpResponseRedirect('/?feed=%s' % feed)
elif tag:
return HttpResponseRedirect('/?tag=%s' % tag)
else:
return HttpResponseRedirect('/')
示例3: untrain
# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import untrain [as 別名]
def untrain(self,bucket,words):
"""
Remove nominated words from the relevant bucket
"""
Bayes.untrain(self,bucket,words)
Bayes.save(self,self.brain)
示例4: Bayes
# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import untrain [as 別名]
from reverend.thomas import Bayes
guesser = Bayes()
guesser.train('fish', 'salmon trout cod carp')
guesser.train('fowl', 'hen chicken duck goose')
guesser.guess('chicken tikka marsala')
guesser.untrain('fish','salmon carp')
示例5: Bayes
# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import untrain [as 別名]
brain = Bayes()
brain.load('fish.db')
tag = 'Dead'
posts = Post.objects.filter(read=read)
posts = posts.filter(tags__in=tag)
#brain.train('Dead', post.summary)
t1 = Tag.objects.get(id=flag)
for post in posts:
t1 = Tag.objects.get(id=flag)
if t1 in post.tags.all() and not feed:
post.tags.remove(t1)
post.read = not t1.read
brain.untrain(t1.name, post.summary)
else:
post.tags.add(t1)
post.read = t1.read
brain.train(t1.name, post.summary)
post.save()
flag = "Weather"
t1 = Tag.objects.get(name=flag)
keyword = "weather"
for post in posts:
if keyword in post.title.lower():
post.tags.add(t1)
post.dead = True
brain.train(t1.name, post.title+post.summary)