當前位置: 首頁>>代碼示例>>Python>>正文


Python Bayes.save方法代碼示例

本文整理匯總了Python中reverend.thomas.Bayes.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Bayes.save方法的具體用法?Python Bayes.save怎麽用?Python Bayes.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在reverend.thomas.Bayes的用法示例。


在下文中一共展示了Bayes.save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: untrained

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [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    
開發者ID:3dfxmadscientist,項目名稱:odoo-extra-1,代碼行數:36,代碼來源:crm_bayes.py

示例2: retrain

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
def retrain(request):
    # Retrain your brain
    user = User.objects.get(user=request.user)
    posts = Post.objects.filter(user=user)
    bayes = Brain.objects.get(user=user)
    brain = Bayes()
    #brain.loads(base64.decodestring(bayes.data))

    tagcount = 0
    # retrain the brain based on existing tags
    for post in posts:
        print post.title, "::",
        for tag in post.tags.all():
            text = "%s %s %s" % (post.title, post.author, post.summary)
            brain.train(tag, text)
            tagcount += 1
            print tag,
        print
    brain.save('%s.db' % user)
    bayes.data = base64.encodestring(brain.saves())
    bayes.save()

    message = 'Found %s tags' % tagcount
    params = {'Messages': [message,]}
    return response(request, 'mainapp/index.html', params)
開發者ID:hollerith,項目名稱:freeder,代碼行數:27,代碼來源:views.py

示例3: treinar

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
def treinar():

    print """>>> Carregando categorias..."""
    CATEGORIAS = os.listdir('./data')
    if '.svn' in CATEGORIAS:
        CATEGORIAS.remove('.svn')


    print ">>> Instanciando treinador\n"    
    guesser = Bayes()
    try:
        for categoria in CATEGORIAS:
            print ">>> Treinando categoria %s" % categoria
            arquivos = os.listdir("%s/%s" % (CAMINHO_CATEGORIAS, categoria))
            if '.svn' in arquivos:
                arquivos.remove('.svn')
            for arquivo in arquivos:
                arquivo = open('%s/%s/%s' % (CAMINHO_CATEGORIAS, categoria, arquivo), 'r')               
                texto = arquivo.read()
                guesser.train(categoria, texto)
        print "\n>>> Salvando base de conhecimento...\n"
        guesser.save("conhecimento.bay")
        print "Voil?!\n"
    except:
        print "N?o foi poss?vel treinar a base"
開發者ID:rocel,項目名稱:stage,代碼行數:27,代碼來源:treinador.py

示例4: train

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
 def train(self,bucket,words):
   """
   Nominate a bucket to which the words apply, and train accordingly
   """
   if bucket != "" and words != "":
     try:
       Bayes.train(self,bucket,words)
       Bayes.save(self,self.brain)
     except:
       print "Failed to learn"
   else:
     return None
開發者ID:Erkan-Yilmaz,項目名稱:grokitbot,代碼行數:14,代碼來源:AIMLBayes.py

示例5: __init__

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
  def __init__(self,name):
    Bayes.__init__(self)

    self.brain = name + '.bay'

    try:
      Bayes.load(self,self.brain)
      print "[Bayes] Brain loaded ok"
    except:
      print "[Alert] Failed to load bayesian brain - %s, creating it now" % self.brain
      Bayes.save(self,self.brain)
      Bayes.load(self,self.brain)
開發者ID:Erkan-Yilmaz,項目名稱:grokitbot,代碼行數:14,代碼來源:AIMLBayes.py

示例6: action_train

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
 def action_train(self, cr, uid, ids, context=None):
     cat_obj = self.pool.get('crm.bayes.categories')
     group_obj = self.pool.get('crm.bayes.group')
     message_obj = self.pool.get('crm.bayes.test.guess')
     
     for id in ids:
         cat_id = self.read(cr, uid, id, ['category_id','name'])         
         cat_id = cat_id[0]['category_id']
         if  result :
             max_list = max(result, key=lambda k: k[1])
             if cat_id:
                 cat_guess_msg = cat_obj.read(cr, uid, cat_id, ['train_messages'])
                 cat_obj.write(cr, uid, cat_id, {'train_messages' :cat_guess_msg['train_messages'] + 1})
             if max_list[1] > 0 and not cat_id:
                 cat_id = cat_obj.search(cr, uid, [('name','=',max_list[0])])[0]
                 cat_guess_msg = cat_obj.read(cr, uid, cat_id, ['guess_messages'])
                 cat_obj.write(cr, uid, cat_id, {'guess_messages' :cat_guess_msg['guess_messages'] + 1})
                 self.write(cr, uid, ids, {'category_id':cat_id})
         if cat_id :
             cat_rec = cat_obj.read(cr, uid, cat_id, [])
             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.train(cat_rec['name'], message_obj.read(cr, uid, id)[0]['name'])
             guesser.save(file_path+"crm_bayes.bay")
             myfile = file(file_path+"crm_bayes.bay", 'r')
             data=""
             for fi in myfile.readlines():
                 data += fi 
             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 not rec[0]['tot_guess']:
                 rec[0]['tot_guess'] =0
             percantage = float(rec[0]['tot_guess'] *100)  / float(rec[0]['tot_guess'] + rec[0]['tot_train'])
             group_obj.write(cr, uid, cat_rec['group_id'][0], {'train_data': data,'automate_test':percantage})            
         else :
             raise osv.except_osv(_('Error !'),_('Please Select Category! '))
     return {
         'view_type': 'form', 
         "view_mode": 'form', 
         'res_model': 'crm.bayes.train.message', 
         'type': 'ir.actions.act_window', 
         'target':'new', 
      }
開發者ID:3dfxmadscientist,項目名稱:odoo-extra-1,代碼行數:54,代碼來源:crm_bayes.py

示例7: treino

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
def treino (self):    
        banco_do_jornal = Server()
        genero=[banco_do_jornal[doc] for doc in GENEROS]
         #treinando o reverend
        from reverend.thomas import Bayes
        guesser = Bayes()
        guesser.train('artigo', ' '.join(genero[0][doc]['texto'] for doc in genero[0]))
        guesser.train('resenha',' '.join(genero[6][doc]['texto'] for doc in genero[6]))  
        guesser.train('noticia',' '.join(genero[1][doc]['texto'] for doc in genero [1]))
        guesser.train('cronica',' '.join(genero[5][doc]['texto']for doc in genero[5] if 'texto' in genero[5][doc] ))
        guesser.train('horoscopo',' '.join(genero[3][doc]['texto']for doc in genero[3]))
        guesser.train('manchete',' '.join(genero[2][doc]['titulo']for doc in genero[2]))
        guesser.train('receita',' '.join(genero[4][doc]['texto']for doc in genero[4]))
        guesser.save('my_guesser.bay')
        variavel = guesser.guess('Cidad?o se descuidou e roubaram seu celular. Como era um executivo e n?o sabia mais viver sem celular, ficou furioso. Deu parte do roubo, de Quara?.? Pois ?.? Carol.? Hein?? Meu nome. ? Carol.? Ah. Voc?s s?o...? N?o, n?o. Nos conhecemos h? pouco.? Escute Carol. Eu trouxe uma encomenda para o Amleto. De Quara?. Uma pessegada, mas n?o me lembro do endere?o.')
        print  'Resultado = ', variavel
開發者ID:rocel,項目名稱:stage,代碼行數:18,代碼來源:Python-1.py

示例8: treino

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
 def treino (self):    
     banco_do_jornal = Server()
     genero=[banco_do_jornal[doc] for doc in GENEROS]
      #treinando o reverend
     from reverend.thomas import Bayes
     guesser = Bayes()
     guesser.train('artigo', ' '.join(genero[0][doc]['texto'] for doc in genero[0]))
     guesser.train('resenha',' '.join(genero[6][doc]['texto'] for doc in genero[6]))  
     guesser.train('noticia',' '.join(genero[1][doc]['texto'] for doc in genero [1]))
     guesser.train('cronica',' '.join(genero[5][doc]['texto']for doc in genero[5] if 'texto' in genero[5][doc] ))
     guesser.train('horoscopo',' '.join(genero[3][doc]['texto']for doc in genero[3]))
     guesser.train('manchete',' '.join(genero[2][doc]['titulo']for doc in genero[2]))
     guesser.train('receita',' '.join(genero[4][doc]['texto']for doc in genero[4]))
     guesser.save('my_guesser.bay')
     variavel = guesser.guess('Bolo de chocolate :ingredientes : 6 ovos, 2 xicaras de farinha, 1 colher de achocolatado, 1 lata de leite condensado, 2 copos de leite e 3 colheres de açucar')
     print  'Resultado = ', variavel
開發者ID:rocel,項目名稱:stage,代碼行數:18,代碼來源:discriminador+(Neulolog+Rede's+conflicted+copy+2010-10-06).py

示例9: get_db

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
def get_db(private_path, username):
  path = os.path.join(os.path.join(private_path, username), 'spam.bayes')
  guesser = Bayes()

  # load the spam DB
  try:
    guesser.load(path)
  except IOError:
    print "Creating a new spam filter database"

    parent_directory = os.path.dirname(path)
    if not os.path.isdir(parent_directory):
      os.makedirs(parent_directory)

    guesser.save(path)

  return guesser, path
開發者ID:Acidburn0zzz,項目名稱:helloworld,代碼行數:19,代碼來源:spam.py

示例10: treino

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
    def treino (self):    
        banco_do_jornal = Server()
        genero=[banco_do_jornal[doc] for doc in GENEROS]
        #dicionários
        dicionario_artigo={'enunciados de opiniao':'eu acredito''eu acho''nós entendemos que'}
        dicionario_resenha={'auxiliar modal':'pode''deve','lexico':'filme''peça''livro''artista'}
        dicionario_horoscopo={'lexico':'signo''peixes''áries''capricórnio''escorpião''cancer''gêmeos''touro''libra''sargitário''aquario''planeta''mercurio''vênus''marte''jupter''saturno''urano''netuno''ascendente''amor''saúde''trabalho''carta''sorte''dinheiro'}
        dicionario_noticia={'marcadores de data':'janeiro''fevereiro''março''abril''maio''junho''julho''agosto''setembro''outubro''novembro''dezenbro'}
        
         #treinando o reverend
        from reverend.thomas import Bayes
        guesser = Bayes()
        guesser.train('artigo', ' '.join(genero[0][doc]['texto'] for doc in genero[0]) )
        guesser.train('resenha',' '.join(genero[6][doc]['texto'] for doc in genero[6]))  
        guesser.train('noticia',' '.join(genero[1][doc]['texto'] for doc in genero [1]))
        guesser.train('cronica',' '.join(genero[5][doc]['texto']for doc in genero[5] if 'texto' in genero[5][doc] ))
        guesser.train('horoscopo',' '.join(genero[3][doc]['texto']for doc in genero[3]))
        guesser.train('manchete',' '.join(genero[2][doc]['titulo']for doc in genero[2]))
        guesser.train('receita',' '.join(genero[4][doc]['texto']for doc in genero[4]))
        guesser.save('my_guesser.bay')
        variavel = guesser.guess('Lía, Claudia e Dourado se enfrentam no oitavo paredão do BBB10, que acontecerá nesta terça (2)Lia foi a escolha do líder Michel, que justificou que sua opinião vem sendo formada ao longo do jogo. Cacau foi eliminada, pois foram 80% dos votos contra ela, então ela saiu, muitas pessoas não queriam que ela saisse mais foram os votos que decidiram a derrota da cacau (Cláudia)')

        print  'Resultado = ', variavel
開發者ID:rocel,項目名稱:stage,代碼行數:25,代碼來源:discriminador.py

示例11: Bayes

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
from reverend.thomas import Bayes
guesser = Bayes()
guesser.train('french', 'le la les du un une je il elle de en')
guesser.train('german', 'der die das ein eine')
guesser.train('spanish', 'el uno una las de la en')
guesser.train('english', 'the it she he they them are were to')
guesser.guess('they went to el cantina')
guesser.guess('they were flying planes')
guesser.train('english', 'the rain in spain falls mainly on the plain')
guesser.save('my_guesser.bay')
開發者ID:Br3nda,項目名稱:pythoscope,代碼行數:12,代碼來源:Reverend_poe_from_homepage.py

示例12: Bayes

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
from reverend.thomas import Bayes
guesser = Bayes()

f = open("spam.log",'r')
for line in f:
  guesser.train('spam', line.strip())

f = open("notspam.log",'r')
for line in f:
  guesser.train('notspam', line.strip())

guesser.save('spam.bay')
開發者ID:imclab,項目名稱:ask-tell,代碼行數:14,代碼來源:spamfilter.py

示例13: __init__

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
class BayesianClassifier:

  POSITIVE = POSITIVE
  NEGATIVE = NEGATIVE
  NEUTRAL  = NEUTRAL

  THRESHHOLD = 0.1
  guesser = None

  def __init__(self):
    self.guesser = Bayes()

  def train(self, example_tweets):
    for t in example_tweets:
      self.guesser.train(t.sentiment, t.text)

    self.guesser.train(POSITIVE, "cool")
    self.guesser.train(POSITIVE, "Woo")
    self.guesser.train(POSITIVE, "quite amazing")
    self.guesser.train(POSITIVE, "thks")
    self.guesser.train(POSITIVE, "looking forward to")
    self.guesser.train(POSITIVE, "damn good")
    self.guesser.train(POSITIVE, "frickin ruled")
    self.guesser.train(POSITIVE, "frickin rules")
    self.guesser.train(POSITIVE, "Way to go")
    self.guesser.train(POSITIVE, "cute")
    self.guesser.train(POSITIVE, "comeback")
    self.guesser.train(POSITIVE, "not suck")
    self.guesser.train(POSITIVE, "prop")
    self.guesser.train(POSITIVE, "kinda impressed")
    self.guesser.train(POSITIVE, "props")
    self.guesser.train(POSITIVE, "come on")
    self.guesser.train(POSITIVE, "congratulation")
    self.guesser.train(POSITIVE, "gtd")
    self.guesser.train(POSITIVE, "proud")
    self.guesser.train(POSITIVE, "thanks")
    self.guesser.train(POSITIVE, "can help")
    self.guesser.train(POSITIVE, "thanks!")
    self.guesser.train(POSITIVE, "pumped")
    self.guesser.train(POSITIVE, "integrate")
    self.guesser.train(POSITIVE, "really like")
    self.guesser.train(POSITIVE, "loves it")
    self.guesser.train(POSITIVE, "yay")
    self.guesser.train(POSITIVE, "amazing")
    self.guesser.train(POSITIVE, "epic flail")
    self.guesser.train(POSITIVE, "flail")
    self.guesser.train(POSITIVE, "good luck")
    self.guesser.train(POSITIVE, "fail")
    self.guesser.train(POSITIVE, "life saver")
    self.guesser.train(POSITIVE, "piece of cake")
    self.guesser.train(POSITIVE, "good thing")
    self.guesser.train(POSITIVE, "hawt")
    self.guesser.train(POSITIVE, "hawtness")
    self.guesser.train(POSITIVE, "highly positive")
    self.guesser.train(POSITIVE, "my hero")
    self.guesser.train(POSITIVE, "yummy")
    self.guesser.train(POSITIVE, "awesome")
    self.guesser.train(POSITIVE, "congrats")
    self.guesser.train(POSITIVE, "would recommend")
    self.guesser.train(POSITIVE, "intellectual vigor")
    self.guesser.train(POSITIVE, "really neat")
    self.guesser.train(POSITIVE, "yay")
    self.guesser.train(POSITIVE, "ftw")
    self.guesser.train(POSITIVE, "I want")
    self.guesser.train(POSITIVE, "best looking")
    self.guesser.train(POSITIVE, "imrpessive")
    self.guesser.train(POSITIVE, "positive")
    self.guesser.train(POSITIVE, "thx")
    self.guesser.train(POSITIVE, "thanks")
    self.guesser.train(POSITIVE, "thank you")
    self.guesser.train(POSITIVE, "endorse")
    self.guesser.train(POSITIVE, "clearly superior")
    self.guesser.train(POSITIVE, "superior")
    self.guesser.train(POSITIVE, "really love")
    self.guesser.train(POSITIVE, "woot")
    self.guesser.train(POSITIVE, "w00t")
    self.guesser.train(POSITIVE, "super")
    self.guesser.train(POSITIVE, "wonderful")
    self.guesser.train(POSITIVE, "leaning towards")
    self.guesser.train(POSITIVE, "rally")
    self.guesser.train(POSITIVE, "incredible")
    self.guesser.train(POSITIVE, "the best")
    self.guesser.train(POSITIVE, "is the best")
    self.guesser.train(POSITIVE, "strong")
    self.guesser.train(POSITIVE, "would love")
    self.guesser.train(POSITIVE, "rally")
    self.guesser.train(POSITIVE, "very quickly")
    self.guesser.train(POSITIVE, "very cool")
    self.guesser.train(POSITIVE, "absolutely love")
    self.guesser.train(POSITIVE, "very exceptional")
    self.guesser.train(POSITIVE, "so proud")
    self.guesser.train(POSITIVE, "funny")
    self.guesser.train(POSITIVE, "recommend")
    self.guesser.train(POSITIVE, "so proud")
    self.guesser.train(POSITIVE, "so great")
    self.guesser.train(POSITIVE, "so cool")
    self.guesser.train(POSITIVE, "cool")
    self.guesser.train(POSITIVE, "wowsers")
    self.guesser.train(POSITIVE, "plus")
    self.guesser.train(POSITIVE, "liked it")
#.........這裏部分代碼省略.........
開發者ID:m1ck,項目名稱:hottrends,代碼行數:103,代碼來源:bayes.py

示例14: load_csv_to_bayes

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
    for line in reader:
        body = line[1]
        if line[2] == "visible":
            status = "visible"
        else:
            status = "moderated"
        clean_body = re.sub("<[^>]*>","",body)
        guesser.train(status, clean_body)


try:
    guesser.load('dataset.dat')
except IOError as e:
    load_csv_to_bayes('good.csv')
    load_csv_to_bayes('bad.csv')
    guesser.save('dataset.dat')


from flask import Flask, request
from flask import render_template
app = Flask(__name__)

@app.route("/moderate")
def moderate():
    if request.args.has_key('callback'):
        wrapper = request.args.get('callback')+"(%s)"
    else:
        wrapper = "%s"
    results = guesser.guess(request.args.get('body'))
    return wrapper % (json.dumps(results))
開發者ID:bruntonspall,項目名稱:automoderator,代碼行數:32,代碼來源:moderation-api.py

示例15: save

# 需要導入模塊: from reverend.thomas import Bayes [as 別名]
# 或者: from reverend.thomas.Bayes import save [as 別名]
 def save(self):
   """
   Save the brain to disk
   """
   Bayes.save(self,self.brain)
開發者ID:Erkan-Yilmaz,項目名稱:grokitbot,代碼行數:7,代碼來源:AIMLBayes.py


注:本文中的reverend.thomas.Bayes.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。