【问题标题】:ImportError: cannot import name 'countVectorizer' from 'sklearn.feature_extraction.textImportError:无法从“sklearn.feature_extraction.text”导入名称“countVectorizer”
【发布时间】:2020-08-17 04:57:47
【问题描述】:

代码

import numpy as np
from sklearn.feature_extraction.text import countVectorizer
count=countVectorizer
docs=np.array(['The sun is shinning',
               'The weather is sweet',
               'The sun is shinning,The weather is sweet, and one and one is two'])
bag= count.fit_transform(docs)

错误输出

ImportError                               Traceback (most recent call last)
<ipython-input-1-e322748c3b4c> in <module>
      1 import numpy as np
----> 2 from sklearn.feature_extraction.text import countVectorizer
      3 count=countVectorizer
      4 docs=np.array(['The sun is shinning',
      5                'The weather is sweet',

ImportError: cannot import name 'countVectorizer' from 'sklearn.feature_extraction.text' (C:\ProgramData\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py)

声明 我收到此错误帮助我解决它。我在 anaconda 导航器提示符中使用 jupyter notebook。我安装了最新版本的 scikit-learn 但我也遇到了相同的导入错误。然后还使用 Anaconda 命令提示符安装和卸载了 scikit-learn

【问题讨论】:

  • 这是CountVectorizer 而不是countVectorizer(Python 区分大小写)。
  • 谢谢@ayhan 我错过了它对代码的一些额外更改

标签: python scikit-learn countvectorizer


【解决方案1】:

从 sklearn.feature_extraction.text 导入 CountVectorizer

工作中

【讨论】:

    猜你喜欢
    • 2021-01-25
    • 1970-01-01
    • 2022-01-22
    • 2021-06-30
    • 2020-10-19
    • 2018-08-13
    • 2015-01-26
    • 2020-10-10
    • 2020-02-12
    相关资源
    最近更新 更多