当前位置: 首页>>代码示例>>Python>>正文


Python NaiveBayesClassifier.show_most_informative_features方法代码示例

本文整理汇总了Python中nltk.NaiveBayesClassifier.show_most_informative_features方法的典型用法代码示例。如果您正苦于以下问题:Python NaiveBayesClassifier.show_most_informative_features方法的具体用法?Python NaiveBayesClassifier.show_most_informative_features怎么用?Python NaiveBayesClassifier.show_most_informative_features使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nltk.NaiveBayesClassifier的用法示例。


在下文中一共展示了NaiveBayesClassifier.show_most_informative_features方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: defaultdict

# 需要导入模块: from nltk import NaiveBayesClassifier [as 别名]
# 或者: from nltk.NaiveBayesClassifier import show_most_informative_features [as 别名]
    feature_freqdist = defaultdict(FreqDist)
    feature_values = defaultdict(set)
    num_samples = len(train_samples) / 2
    for token, counts in labeled_features.items():
        for label in ['neg','pos']:
            feature_freqdist[label, token].inc(True, count=counts[label])
            feature_freqdist[label, token].inc(None, num_samples - counts[label])
            feature_values[token].add(None)
            feature_values[token].add(True)
    for item in feature_freqdist.items():
        print item[0],item[1]
    feature_probdist = {}
    for ((label, fname), freqdist) in feature_freqdist.items():
        probdist = ELEProbDist(freqdist, bins=len(feature_values[fname]))
        feature_probdist[label,fname] = probdist
    return feature_probdist


labeled_features = get_labeled_features(train_samples)

label_probdist = get_label_probdist(labeled_features)

feature_probdist = get_feature_probdist(labeled_features)

classifier = NaiveBayesClassifier(label_probdist, feature_probdist)

for sample in test_samples:
    print "%s | %s" % (sample, classifier.classify(gen_bow(sample)))

classifier.show_most_informative_features()
开发者ID:imclab,项目名称:happyminions,代码行数:32,代码来源:sentiment_model.py


注:本文中的nltk.NaiveBayesClassifier.show_most_informative_features方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。