Python 3.x ';SklearnClassifier';对象没有属性';批量分类';在NLTK中
我试图使用NLTK的SklearnClassifier和BernoulliNB对数据进行分类。这是一些代码:Python 3.x ';SklearnClassifier';对象没有属性';批量分类';在NLTK中,python-3.x,scikit-learn,classification,nltk,Python 3.x,Scikit Learn,Classification,Nltk,我试图使用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]
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'
回溯(最近一次呼叫最后一次):
文件“G:/pycharm/quanbu.py”,第53行,在
打印('BernoulliNB精度为%f'%score(BernoulliNB()))
文件“G:/pycharm/quanbu.py”,第51行,在分数中
pred=分类器。批处理分类(dev)
AttributeError:“SklearnClassifier”对象没有“batch\u Classifier”属性
我使用的是python3.5.2、nltk3.2.1、scikit learn 0.18。您已经看到了过时的文档。使用nltk 3时,名称更改为
classify\u many()
。(类似地,在其他模块中,batch\u pos\u tag()
和batch\u parse()
分别更改为pos\u tag\u sents()
和parse\u sents()
)看得更好,因为您刚刚开始,还没有代码可移植:找到您需要的任何文档的当前版本。谢谢大家,我已经决定了。