一种多功能朴素贝叶斯分类器

mfnbc的Python项目详细描述


关于数学

这个软件包计算一组简单的算法来计算一个语料库中一组文本上一组特征的最终后验概率。

因此,对于语料库中的每个文本,包将查看中的单词是否包含在提供的似然表中。如果找到它,则使用Bayesian statistics更新每个特征的后验概率。

https://research-it.wharton.upenn.edu/wp-content/uploads/2016/12/eq1.gif

其中

https://research-it.wharton.upenn.edu/wp-content/uploads/2016/12/eq2.gif

是:

https://research-it.wharton.upenn.edu/wp-content/uploads/2016/12/eq3.gif

要求

python=3.3

安装

pip install mfnbc

设置(似然输入文件)

假设您有一个基于单词的似然表(csv文件),其中 标题由文本单词Word和其余的 列是要分类的功能。

例如:

WordAnimalHumanPlant
cat0.330.030.05
dog0.330.020.05
leaves0.050.030.4
tree0.050.020.4
man0.120.450.05
women0.120.450.05

设置(未标记的数据文件)

IDText
1The cat is my pet and he is lovely. A dog will not do.
2The man and women had a cat and lived under a tree
3The tree had lots of leaves
4A man lives under a tree with many leaves. A women has a cat as a pet
5The dog and cat chase the man under the tree
6The man and women live in a house.

键的标题是Text任何其他字段都将是 在输出文件中包括未修改的。

导入

frommfnbcimportMFNBC

实例化

m=MFNBC(<likelihoods_input_file-locationofLikelihoodtable(str)>,<unlabeled_data_file-Locationofunlabeleddatafile(str)>,<verboseoutput-Turnonofoffverboseoutput,default:off><outputfilename-defaultstoout.csv,(str)>

示例

m=MFNBC('likeli_sample.csv','input_sample.csv',False,'my_output.csv')m.read_likelihoods()m.calc_posteriors()m.write_csv()

或者您可以在一个命令中完成所有操作

m=MFNBC('likeli_sample.csv','input_sample.csv',False).write_csv()

示例结果

IDTextAnimalHumanPlant
1The cat is my pet and he is lovely. A dog will not do.0.9723214290.0053571430.022321429
2The man and women had a cat and lived under a tree0.5807870940.29699340.122219506
3The tree had lots of leaves0.015328020.0036787250.980993256
4A man lives under a tree with many leaves. A women has a cat as a pet0.3344123860.10260380.562983814
5The dog and cat chase the man under the tree0.9218397290.007618510.070541761
6The man and women live in a house.0.0656335460.9229717410.011394713

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
由于java的原因,maven无法运行代码。lang.NoClassDefFoundError:com/fasterxml/jackson/annotation/JsonMerge   Android项目中的java Creative SDK图像编辑器UI   java如何在Android Studio中使用DataOutputStream上传文件并将其他参数传递到web服务器   java倒计时服务打开时崩溃   java将RubyonRails项目转换为JRubyonRails项目   java我的图库意图是不显示图像?为什么?   java如何在春季启动时跳过mongodb/   java@Autowired在Spring中是如何实现的   甲骨文Akka java。util。同时发生的timeoutexception线程池频繁超时   java maven依赖项对spring启动应用程序有何影响?   java Firestore执行复合查询,未截获事件“已修改”   java ItemStreamException:未能初始化读取器,原因是:IllegalStateException:流已初始化。重新开放前关闭   java将空标记解组到集合的新实例中   使用AspectJ的java新手:无法调用aspect   java查找棋类游戏的所有组合   你为什么要这样做and==与Java中的equals方法不一样吗?   如何对使用JavaUUID的代码进行单元测试?