【发布时间】:2015-10-15 19:14:00
【问题描述】:
我正在使用 Python 2.7 和 Jacob Perkins 创建的名为 NLTK Trainer 的出色工具。我已经成功使用了 NaiveBayes 分类器,但是当我尝试使用各种 scikit-learn 分类器时,它会抛出错误消息。请帮忙。这是我的代码和相关的错误消息。
C:\WINDOWS\system32>C:\Python27\python C:\Users\ned\Desktop\nltk-trainer-master
\train_classifier.py --instances files --fraction 0.75 --no-pickle --min_score 2
--ngrams 1 2 3 --show-most-informative 10 movie_reviews --classifier sklearn.Mu
ltinomialNB
training sklearn.MultinomialNB classifier
C:\Python27\lib\site-packages\numpy\core\fromnumeric.py:2499: VisibleDeprecation
Warning: `rank` is deprecated; use the `ndim` attribute or function instead. To
find the rank of a matrix see `numpy.linalg.matrix_rank`.
VisibleDeprecationWarning)
Traceback (most recent call last):
File "C:\Users\ned\Desktop\nltk-trainer-master\train_classifier.py", line 385,
in <module>
print('accuracy: %f' % accuracy(classifier, test_feats))
File "C:\Python27\lib\site-packages\nltk\classify\util.py", line 87, in accura
cy
results = classifier.classify_many([fs for (fs, l) in gold])
File "C:\Python27\lib\site-packages\nltk\classify\scikitlearn.py", line 83, in
classify_many
X = self._vectorizer.transform(featuresets)
File "C:\Users\ned\Desktop\nltk-trainer-master\sklearn\feature_extraction\dict
_vectorizer.py", line 286, in transform
return self._transform(X, fitting=False)
File "C:\Users\ned\Desktop\nltk-trainer-master\sklearn\feature_extraction\dict
_vectorizer.py", line 196, in _transform
result_matrix.sort_indices()
File "C:\Python27\lib\site-packages\scipy\sparse\compressed.py", line 619, in
sort_indices
fn( len(self.indptr) - 1, self.indptr, self.indices, self.data)
File "C:\Python27\lib\site-packages\scipy\sparse\sparsetools\csr.py", line 546
, in csr_sort_indices
return _csr.csr_sort_indices(*args)
TypeError: Array of type 'byte' required. Array of type 'bool' given
然后我使用以下版本: Python 2.7.10
Python 2.7 numpy 1.9.1
Python 2.7 scikit-learn 0.16.1
Python 2.7 scipy 0.10.1
Python 2.7 NLTK 3.0.4
Argparse 1.3.0
*** 感谢大家的帮助。问题确实是一个过时的库。我从这里安装了最新版本:http://www.lfd.uci.edu/~gohlke/pythonlibs/ 并使用此处的简单安装指南: https://www.youtube.com/watch?v=jnpC_Ib_lbc
【问题讨论】:
标签: python scikit-learn nltk