我正在对来自葡萄牙历史的维基百科页面上的句子尝试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吗?