【发布时间】: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