【问题标题】:TfidfVectorizer.fit_transform giving type errorTfidfVectorizer.fit_transform 给出类型错误
【发布时间】:2016-10-08 10:27:23
【问题描述】:

我是 scikit-learn 的新手。我需要计算大型语料库的 tf-idf 向量。但在开始之前,我尝试编写一些不超过 5-6 个单词的小文档。我写的具体代码如下:

from sklearn.feature_extraction.text 
import TfidfVectorizer
vectorizer = TfidfVectorizer(min_df=1)
vectors = vectorizer.fit_transform(docList)

它在我的笔记本电脑上运行良好,但是当我在服务器上运行它时产生以下错误:

Traceback (most recent call last):
  File "temp1.py", line 49, in <module>
    tfidf_vectorizer.fit_transform(docList)
  File "/usr/lib64/python2.6/site-packages/sklearn/feature_extraction/text.py", line 1285, in fit_transform
    X = super(TfidfVectorizer, self).fit_transform(raw_documents)
  File "/usr/lib64/python2.6/site-packages/sklearn/feature_extraction/text.py", line 825, in fit_transform
max_features)
  File "/usr/lib64/python2.6/site-packages/sklearn/feature_extraction/text.py", line 697, in _limit_features
    dfs = _document_frequency(X)
  File "/usr/lib64/python2.6/site-packages/sklearn/feature_extraction/text.py", line 491, in _document_frequency
    return bincount(X.indices, minlength=X.shape[1])
  File "/usr/lib64/python2.6/site-packages/sklearn/utils/fixes.py", line 345, in bincount
    return np.bincount(x, weights, minlength)
TypeError: function takes at most 2 arguments (3 given)

这是安装的sklearn版本有问题吗?我的笔记本电脑上安装了 0.17.1,服务器上安装了 sklearn 0.16.1。由于我的语料很大,我必须在服务器上运行,否则我自然会面临内存问题。

任何对此问题的见解将不胜感激。 谢谢你:)

【问题讨论】:

  • 服务器上安装了哪个版本的numpy?

标签: python scikit-learn tf-idf


【解决方案1】:

我认为这与 numpy 安装错误有关,报告here

您可以运行测试并检查(需要鼻子):

pip install nose
nosetests -v numpy
nosetests -v sklearn

如果是这种情况,您需要删除 numpy(可能还包括 scikit-learn)并使用推荐的说明重新安装它们:http://scikit-learn.org/stable/install.html

使用 conda 也是一个不错的选择:https://www.continuum.io/downloads

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 2013-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多