<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Naive Bayesian Classifier樸素貝葉斯分類器

          聯(lián)合創(chuàng)作 · 2023-09-26 04:18

          這是一個(gè)非常簡(jiǎn)單的 Python 庫,實(shí)現(xiàn)了樸素貝葉斯分類器。

          示例代碼:

          """
          Suppose you have some texts of news and know their categories.
          You want to train a system with this pre-categorized/pre-classified 
          texts. So, you have better call this data your training set.
          """
          from naiveBayesClassifier import tokenizer
          from naiveBayesClassifier.trainer import Trainer
          from naiveBayesClassifier.classifier import Classifier
          
          newsTrainer = Trainer(tokenizer.Tokenizer(stop_words = [], signs_to_remove = ["?!#%&"]))
          
          # You need to train the system passing each text one by one to the trainer module.
          newsSet =[
              {'text': 'not to eat too much is not enough to lose weight', 'category': 'health'},
              {'text': 'Russia is trying to invade Ukraine', 'category': 'politics'},
              {'text': 'do not neglect exercise', 'category': 'health'},
              {'text': 'Syria is the main issue, Obama says', 'category': 'politics'},
              {'text': 'eat to lose weight', 'category': 'health'},
              {'text': 'you should not eat much', 'category': 'health'}
          ]
          
          for news in newsSet:
              newsTrainer.train(news['text'], news['category'])
          
          # When you have sufficient trained data, you are almost done and can start to use
          # a classifier.
          newsClassifier = Classifier(newsTrainer.data, tokenizer.Tokenizer(stop_words = [], signs_to_remove = ["?!#%&"]))
          
          # Now you have a classifier which can give a try to classifiy text of news whose
          # category is unknown, yet.
          unknownInstance = "Even if I eat too much, is not it possible to lose some weight"
          classification = newsClassifier.classify(unknownInstance)
          
          # the classification variable holds the possible categories sorted by 
          # their probablity value
          print classification
          瀏覽 18
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美一级裸体视频 | 国产毛片在线视频 | 亚洲国产精品成人综合色丿丿 | 欧美性爱天天操 | 亚洲精品国产精品国自产网站 |