我在这篇文章中看到了几个问题 .
TfidfVectorizer中的不同参数如何相互作用?
你真的必须用它来培养一种直觉感(无论如何都是我的经验) .
TfidfVectorizer是一个单词的方法 . 在NLP中,单词序列及其窗口很重要;这种破坏了一些背景 .
How do I control what tokens get outputted?
将 ngram_range 设置为(1,1)仅输出一个单词令牌,(1,2)表示单字和双字令牌,(2,3)表示双字和三字令牌等 .
ngram_range 与 analyzer 携手合作 . 将 analyzer 设置为"word"以输出单词和短语,或将其设置为"char"以输出字符ngrams .
如果您希望输出同时具有"word"和"char"功能,请使用sklearn的FeatureUnion . 示例here .
How do I remove unwanted stuff?
使用 stop_words 删除不太有意义的英语单词 .
sklearn使用的停用词列表可在以下位置找到:
from sklearn.feature_extraction.stop_words import ENGLISH_STOP_WORDS
删除停用词的逻辑与这些词没有很多意义的事实有关,并且它们在大多数文本中都出现了很多:
[('the', 79808),
('of', 40024),
('and', 38311),
('to', 28765),
('in', 22020),
('a', 21124),
('that', 12512),
('he', 12401),
('was', 11410),
('it', 10681),
('his', 10034),
('is', 9773),
('with', 9739),
('as', 8064),
('i', 7679),
('had', 7383),
('for