【问题标题】:show_most_informative_features() errors with exception in python 3.8在 python 3.8 中出现异常的 show_most_informative_features() 错误
【发布时间】:2020-08-08 15:12:03
【问题描述】:

问题:

 "line 188, in most_informative_features self._most_informative_features = sorted( TypeError: '<' not supported between instances of 'str' and 'tuple'" while using naiveBayes classifier

代码:

print('accuracy:', nltk.classify.util.accuracy(classifier, testdata))
classifier.show_most_informative_features(10)

accuracy 打印,但 show_most_informative_features 出错,上述异常表明 naivebayes.py 出错。关于修复的任何想法? 这是发生异常的那一行:既然,在标准 python 库中更改代码不是一个好主意,我在调用函数时是否遗漏了什么?

self._most_informative_features = sorted(
                features, key=lambda feature_: (minprob[feature_]/maxprob[feature_], feature_[0],
                                                feature_[1] in [None, False, True], str(feature_[1]).lower())
            )
        return self._most_informative_features[:n]

【问题讨论】:

    标签: python-3.x sorting typeerror sentiment-analysis naivebayes


    【解决方案1】:

    classifier = nltk.NaiveBayesClassifier.train(training_set) 中的 training_set 应该是一个字典,其中键都是元组(而不是元组和字符串的混合)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-20
      • 1970-01-01
      • 2022-11-22
      • 2014-05-03
      • 2013-02-20
      • 1970-01-01
      相关资源
      最近更新 更多