我正在尝试使用NLTK的SklearnClassifier和BernoulliNB对数据进行分类。这是一些代码:
train = posFeatures[174:]+negFeatures[174:]+neuFeatures[174:]
devtest = posFeatures[124:174]+negFeatures[124:174]+neuFeatures[124:174]
test = posFeatures[:124]+negFeatures[:124]+neuFeatures[:124]
dev, tag_dev = zip(*devtest)
def score(classifier):
classifier = SklearnClassifier(classifier)
classifier.train(train)
pred = classifier.batch_classify(dev)
return accuracy_score(tag_dev,pred)
print('BernoulliNB accuracy is %f'%score(BernoulliNB()) )
然后我收到了这个错误:
Traceback (most recent call last):
File "G:/pycharm/quanbu.py", line 53, in <module>
print('BernoulliNB accuracy is %f'%score(BernoulliNB()) )
File "G:/pycharm/quanbu.py", line 51, in score
pred = classifier.batch_classify(dev)
AttributeError: 'SklearnClassifier' object has no attribute 'batch_classify'
我正在使用python3.5.2,nltk3.2.1,scikit-learn 0.18。
答案 0 :(得分:1)
您一直在查看过时的文档。使用nltk 3,名称已更改为classify_many()
。 (同样在其他模块中,batch_pos_tag()
和batch_parse()
分别更改为pos_tag_sents()
和parse_sents()
。)