数学之路(机器学习实践指南)-文本挖掘与NLP(6)
来源:互联网 发布:xp专业版激活软件 编辑:程序博客网 时间:2024/04/30 05:31
def wordfeatures(word): return {"cnword":word}.....classifier=nltk.NaiveBayesClassifier.train(samplewords)#大学所属的类别 http://blog.csdn.net/myhasplprint u"----大学所属的类别-----"print classifier.classify({"cnword":u"大学"})#大脑所属的类别http://blog.csdn.net/myhasplprint u"----大脑所属的类别-----"print classifier.classify({"cnword":u"大脑"})#测试数据分类准确率http://blog.csdn.net/myhasplprint nltk.classify.accuracy(classifier,testwords)#特征0分类最有效的10个词http://blog.csdn.net/myhasplfor wf,mostword in classifier.most_informative_features(10): print mostword,print#为显示utf-8,将show_most_informative_features代码进行修改http://blog.csdn.net/myhaspl#classifier.show_most_informative_features(10) 也可直接调用这句,但是UTF8显示有问题 http://blog.csdn.net/myhaspl cpdist = classifier._feature_probdistprint('Most Informative Features')for (fname, fval) in classifier.most_informative_features(10): def labelprob(l): return cpdist[l, fname].prob(fval) labels = sorted([l for l in classifier._labels if fval in cpdist[l, fname].samples()], key=labelprob) if len(labels) == 1: continue l0 = labels[0] l1 = labels[-1] if cpdist[l0, fname].prob(fval) == 0: ratio = 'INF' else: ratio = '%8.1f' % (cpdist[l1, fname].prob(fval) / cpdist[l0, fname].prob(fval)) print fname+"="+fval, print(('%6s : %-6s = %s : 1.0' % (("%s" % l1)[:6], ("%s" % l0)[:6], ratio))) 运行结果:= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =>|----大学所属的类别-----教育----大脑所属的类别-----科技0.977346278317世界 公司 事先 游戏 之后 领域 采用 学科 里面 技术Most Informative Featurescnword=世界 科技 : 教育 = 20.6 : 1.0cnword=公司 科技 : 教育 = 12.4 : 1.0cnword=事先 科技 : 教育 = 5.8 : 1.0cnword=游戏 科技 : 教育 = 5.8 : 1.0cnword=之后 科技 : 教育 = 4.5 : 1.0cnword=领域 科技 : 教育 = 4.5 : 1.0cnword=采用 科技 : 教育 = 4.5 : 1.0cnword=学科 科技 : 教育 = 4.1 : 1.0cnword=里面 科技 : 教育 = 4.1 : 1.0cnword=技术 科技 : 教育 = 4.1 : 1.0
本博客所有内容是原创,如果转载请注明来源
http://blog.csdn.net/myhaspl/
朴素贝叶斯分类,对词条分类如上
1 0
- 数学之路(机器学习实践指南)-文本挖掘与NLP(6)
- 数学之路(机器学习实践指南)-文本挖掘与NLP(1)
- 数学之路(机器学习实践指南)-文本挖掘与NLP(2)
- 数学之路(机器学习实践指南)-文本挖掘与NLP(3)
- 数学之路(机器学习实践指南)-文本挖掘与NLP(4)
- 数学之路(机器学习实践指南)-文本挖掘与NLP(5)
- 数学之路(机器学习实践指南)-深度学习(1)-caffe
- 机器学习:文本挖掘之特征选择
- 数据挖掘 NLP 之 文本挖掘 文本处理 通用流程
- 机器学习与数据挖掘学习之路
- 炼数成金机器读心术之文本挖掘与自然语言处理(附讲义)推荐学习
- 数学之美 - 机器学习实战 书籍 数据挖掘。
- 机器学习实践指南
- 机器学习实践指南
- 机器学习实践指南
- 机器学习实践指南
- 数据挖掘与机器学习 WEKA 应用技术与实践
- 机器学习与数据挖掘之决策树
- Android_Studio快捷键和使用技巧
- 关于python对于aspx网页的post提交
- Sencha Touch 2 在MAC下详细的开发流程
- 屏幕适配
- springboot配置文件加载不到的问题
- 数学之路(机器学习实践指南)-文本挖掘与NLP(6)
- 享元模式
- jQuery表单选择器
- 第14、15课Java数组与方法零基础编程实战课堂笔记
- MAC 上找不到.bash_profile该怎么办?
- 备忘录模式
- 2.4日,学习汇总
- web 关于http://localhost无法访问的可能原因
- 2016蓝桥杯假期任务之《未名湖边的烦恼》