小编kil*_*zio的帖子

scikit-学习TfidfVectorizer忽略某些单词

我正在对来自葡萄牙历史的维基百科页面上的句子尝试TfidfVectorizer。但是我注意到该TfidfVec.fit_transform方法忽略了某些单词。这是我尝试过的句子:

sentence = "The oldest human fossil is the skull discovered in the Cave of Aroeira in Almonda."

TfidfVec = TfidfVectorizer()
tfidf = TfidfVec.fit_transform([sentence])

cols = [words[idx] for idx in tfidf.indices]
matrix = tfidf.todense()
pd.DataFrame(matrix,columns = cols,index=["Tf-Idf"])
Run Code Online (Sandbox Code Playgroud)

数据帧的输出:

在此处输入图片说明

本质上,它忽略了“ Aroeira”和“ Almonda”两个词。

但是我不想让它忽略那些话,那我该怎么办?我在文档中找不到他们谈论此内容的任何地方。

另一个问题是为什么“ the”一词会重复出现?该算法应该只考虑一个“ the”并计算其tf-idf吗?

python nlp tf-idf scikit-learn tfidfvectorizer

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

标签 统计

nlp ×1

python ×1

scikit-learn ×1

tf-idf ×1

tfidfvectorizer ×1