python - 停用词与 sklearn CountVectorizer 中的预处理不一致
问题描述
我一直在尝试使用 sklearn 库中的 Count Vectorizer,但是我收到警告说我使用的西班牙语停用词列表与预处理不一致。
是不是编码问题??
stopwords.txt 文件每行有一个单词,例如:
一个埃尔洛斯...
custom_stop_words = []
with open( "stopwords.txt", "r" ,encoding='latin_1') as fin:
for line in fin.readlines():
custom_stop_words.append( line.strip() )
# note that we need to make it hashable
print("Stopword list has %d entries" % len(custom_stop_words) )
from sklearn.feature_extraction.text import CountVectorizer
# use a custom stopwords list, set the minimum term-document frequency to 20
vectorizer = CountVectorizer(stop_words = custom_stop_words, min_df = 2,strip_accents='unicode',encoding="latin-1")
A = vectorizer.fit_transform(df_final['visita'])
print( "Created %d X %d document-term matrix" % (A.shape[0], A.shape[1]) )
解决方案
推荐阅读
- javascript - 在文本字段extjs中的n个字符之后插入特殊字符
- python - Tensorflow:如何更改张量中的特定值?
- php - 如何使用 ajax Laravel 8 更新总量
- sharepoint - 如何在 Sharepoint 2016 中通过 Visual Web 部件更新项目后重新加载列表?
- ios - 为什么 UIApplication.shared.canOpenURL(url) 可以在一台设备上运行,而不能在另一台设备上运行
- c++ - 查找产品 Hackerearth
- angular - Angular API Single object中如何绑定类别obj、子类别对象和组类别对象数据
- graph - Modelica,什么是 der(x)
- c - 如何从传递给C函数的参数(char *)中获取字符串?
- android - Android 导航布局项左右对齐