Naive Bayesian Classifier 朴素贝叶斯分类器

程序名称:Naive Bayesian Classifier

授权协议: MIT

操作系统: 跨平台

开发语言: Python

Naive Bayesian Classifier 介绍

这是一个非常简单的 Python 库,实现了朴素贝叶斯分类器。

示例代码

"""
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

Naive Bayesian Classifier 官网

https://github.com/muatik/naive-bayes-classifier

相关编程语言

欧盟第7框架计划(FP7)的LarKC项目的目标是开发大规模...
Salad 是一种有效且灵活的实现著名的异常检测方法回...
multilanguage 是一个多语开发工具包,用于缓存多语...
go-cortex 是一个服务,通过倾听你的句子,并视图理...
DKPro Core 是基于 Apache UIMA 框架之上的自然语言...
NLTK 会被自然地看作是具有栈结构的一系列层,这些层...