TfidfTransformer 和停用词

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

from sklearn.feature_extraction.text import TfidfTransformertfidf = 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'

如何解决这个错误?


回答:

我想你是想使用 TfidfVectorizer,它有 stop_words 参数。请参考这里的文档

示例:

from sklearn.feature_extraction.text import TfidfVectorizercorpus = [    '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)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注