小编for*_*win的帖子

如何仅使用 scikit-learn 消除停用词?

我能够让代码吐出一个单词及其频率。但是,我想仅使用 scikit-learn 消除停用词。nltk 在我的工作场所不起作用。有人对如何消除停用词有任何建议吗?

import pandas as pd
df = pd.DataFrame(['my big dog', 'my lazy cat'])
df
         0
0   my big dog
1  my lazy cat

value_list = [row[0] for row in df.itertuples(index=False, name=None)]
value_list
['my big dog', 'my lazy cat']

from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer()
x_train = cv.fit_transform(value_list)
x_train
<2x5 sparse matrix of type '<class 'numpy.int64'>'
with 6 stored elements in Compressed Sparse Row format>
x_train.toarray()
array([[1, 0, 1, 0, 1],
   [0, 1, 0, 1, 1]], dtype=int64) …
Run Code Online (Sandbox Code Playgroud)

python pandas scikit-learn

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

pandas ×1

python ×1

scikit-learn ×1