__initüuu()获得意外的关键字参数“stop峎words”

2024-06-23 03:06:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用scikit learn版本0.14.1计算tf-idf。我的密码是:

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from nltk.corpus import stopwords
import numpy as np
import numpy.linalg as LA

train_set = ["The sky is blue.", "The sun is bright."] #Documents
test_set = ["The sun in the sky is bright sun."] #Query
stopWords = stopwords.words('english')

vectorizer = CountVectorizer(stop_words = stopWords)
#print vectorizer
transformer = TfidfTransformer() 
#print transformer

trainVectorizerArray = vectorizer.fit_transform(train_set).toarray()
testVectorizerArray = vectorizer.transform(test_set).toarray()
print 'Fit Vectorizer to train set', trainVectorizerArray
print 'Transform Vectorizer to test set', testVectorizerArray

transformer.fit(trainVectorizerArray)
print
print transformer.transform(trainVectorizerArray).toarray()

transformer.fit(testVectorizerArray)
print
tfidf = transformer.transform(testVectorizerArray)
print tfidf.todense()

我有个错误:

^{pr2}$

我不明白“停止语”有什么问题,需要帮助吗?在


Tags: thefromtestimportistransformtrainfit
1条回答
网友
1楼 · 发布于 2024-06-23 03:06:42

所以这个错误是我的,我跟随一个在线教程安装了sklearn,得到了0.10版本。根据这个错误,我认为sklearn 0.10版不支持stop_words。 更新到版本0.14.1后,它工作正常!!在

相关问题 更多 >

    热门问题