【问题标题】:TfidfTransformer and stop wordsTfidfTransformer 和停用词
【发布时间】:2020-07-31 18:44:40
【问题描述】:

我正在从sklearn 导入TfidfTransformer 并尝试使用stop_word 参数,但它显示错误。

from sklearn.feature_extraction.text import TfidfTransformer
tfidf = TfidfTransformer(stop_words='english')


TypeError                                 Traceback (most recent call last)
<ipython-input-16-1315a209c082> in <module>
      1 from sklearn.feature_extraction.text import TfidfTransformer
----> 2 tfidf = TfidfTransformer(stop_words='english')

TypeError: __init__() got an unexpected keyword argument 'stop_words'

如何解决这个错误?

【问题讨论】:

  • 根据documentation,TfidfTransformer 没有参数stop_words

标签: python machine-learning scikit-learn sklearn-pandas


【解决方案1】:

我认为您意图使用TfidfVectorizer,它具有参数stop_words。请参阅文档here

例子:

from sklearn.feature_extraction.text import TfidfVectorizer
corpus = [
    'This is the first document.',
    'This document is the second document.',
    'And this is the third one.',
    'Is this the first document?',
]
vectorizer = TfidfVectorizer(stop_words='english')
X = vectorizer.fit_transform(corpus)

【讨论】:

    猜你喜欢
    • 2019-07-12
    • 2014-10-09
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 2023-03-17
    • 2011-09-12
    • 2019-05-05
    相关资源
    最近更新 更多