【问题标题】:NLTK Trainer: Cannot get Scikit-Learn classifiers to workNLTK 培训师:无法让 Scikit-Learn 分类器工作
【发布时间】: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


    【解决方案1】:

    您使用的是 scipy 0.10.1,它有几个版本 - 尝试升级到 scipy 0.14。

    这是它的工作示例以及使用的包的版本...

    $ python
    Python 2.7.10 (default, Jul  5 2015, 14:15:43) 
    [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import scipy
    >>> scipy.__version__
    '0.14.1'
    >>> import numpy
    >>> numpy.__version__
    '1.9.2'
    >>> import sklearn
    >>> sklearn.__version__
    '0.16.1'
    >>> import nltk
    >>> nltk.__version__
    '3.0.4'
    >>> import argparse
    >>> argparse.__version__
    '1.1'
    
    $ python 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.MultinomialNB
    loading movie_reviews
    2 labels: [u'neg', u'pos']
    calculating word scores
    using bag of words from known set feature extraction
    71903 words meet min_score and/or max_feats
    1500 training feats, 500 testing feats
    training sklearn.MultinomialNB with {'alpha': 1.0}
    using dtype bool
    training sklearn.MultinomialNB classifier
    accuracy: 0.788000
    neg precision: 0.918605
    neg recall: 0.632000
    neg f-measure: 0.748815
    pos precision: 0.719512
    pos recall: 0.944000
    pos f-measure: 0.816609
    

    【讨论】:

      【解决方案2】:

      可能相关? https://github.com/scipy/scipy/issues/2058 如果不是,它可能会让您更清楚地说明问题。

      在另一张票中,如果是版本问题,我会对所有内容进行版本检查。我认为现在 Python 3 的开发/支持比 2.7 更积极。

      【讨论】:

        【解决方案3】:

        我注意到这个项目的 github 存储库中有一个问题,并带有确切的错误消息:

        https://github.com/japerk/nltk-trainer/issues/12

        用户说:

        知道了,我在另一台机器上用 diff 训练了分类器 scipy 和/或 sklearn 的版本。

        在您上面的示例中,您似乎在运行的同一台机器上进行了培训,是这样吗?

        【讨论】:

        • 是的,我用的是同一台机器
        猜你喜欢
        • 2015-10-28
        • 1970-01-01
        • 2017-09-27
        • 2021-11-28
        • 2017-12-22
        • 2012-11-11
        • 2022-01-05
        • 1970-01-01
        • 2013-07-04
        相关资源
        最近更新 更多