如何解决停止词与sklearn CountVectorizer中的预处理不一致
我一直在尝试使用sklearn库中的Count Vectorizer,但是我收到警告,我正在使用的西班牙语停用词列表与预处理不一致。
这是编码问题吗?
stopwords.txt文件每行有一个单词,例如:
a 埃尔 洛斯 ...
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]) )
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。