把膳绫擎的所有测试结不雅进行综合可汇总如下:
不合分类器的不合特点选择办法效不雅

- posFeatures = pos_features(bigrams)
- negFeatures = neg_features(bigrams)
用Python 进行机械进修及情感分析,须要用到两个重要的法度榜样包:nltk 和 scikit-learn
所以在经由膳绫擎一系列的分析之后,可以得出如下的结论:
- Bernoulli 朴实贝叶斯分类器效不雅最佳
- 词和双词搭配作为特点时效不雅最好
- 当特点维数为1500时效不雅最好
为了不消每次分类之前都要练习一次数据,所以可以在用开辟集找出最佳分类器后,把最佳分类器存储下来以便今后应用。然后再应用这个分类器对文本进行分类。
一、应用测试集测试分类器的最终效不雅
- word_scores = create_word_bigram_scores() #应用词和双词搭配作为特点
- best_words = find_best_words(word_scores, 1500) #特点维度1500
- posFeatures = pos_features(best_word_features)
- negFeatures = neg_features(best_word_features)
- trainSet = posFeatures[:500] + negFeatures[:500] #应用了更多半据
- testSet = posFeatures[500:] + negFeatures[500:]
- test, tag_test = zip(*testSet)
- def final_score(classifier):
- classifier = SklearnClassifier(classifier)
- classifier.train(trainSet)
- pred = classifier.batch_classify(test)
- return accuracy_score(tag_test, pred)
- print final_score(BernoulliNB()) #应用开辟集中得出的最佳分类器
其结不雅是很给力的:
nltk 重要负粜ウ理特点提取(双词或多词搭配须要应用nltk 来做)和特点选择(须要nltk 供给的统计办法)。
- 0.979166666667
二、把分类器存储下来
(存储分类器和前面没有差别,只是应用了更多的练习数据以便分类器更为精确)
- word_scores = create_word_bigram_scores()
- best_words = find_best_words(word_scores, 1500)
- posFeatures = pos_features(best_word_features)
- negFeatures = neg_features(best_word_features)
- trainSet = posFeatures + negFeatures
- BernoulliNB_classifier = SklearnClassifier(BernoulliNB())
- BernoulliNB_classifier.train(trainSet)
- pickle.dump(BernoulliNB_classifier,
推荐阅读
进修怎么在保护 root 暗码的安然性的同时,为可托用户付与所治理的收集功能和特定办事的权限。我比来写了一个简短的 Bash 法度榜样来将 MP3 文件大年夜一台收集主机的 USB 盘中拷贝到另一台收集主机上去。拷贝出来的>>>详细阅读
本文标题:使用python+机器学习方法进行情感分析(详细步骤)
地址:http://www.17bianji.com/lsqh/40229.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示