scikit-learn 中的 CountVectorizer 和 CharNGramAnalyzer 有什么区别?

What is the difference between CountVectorizer and CharNGramAnalyzer in scikit-learn?

我对 CountVectorizer 和 CharNGramAnalyzer 感到困惑。据我了解,

  1. CountVectorizer 构建一个计数矩阵,其中行是考虑到高维稀疏性的不同单词的出现次数。
  2. CharNGramAnalyzer 构建一个计数矩阵,其中行是不同字符的出现次数。由于它不考虑单词,因此不需要知道单词之间的分隔,并且适用于英语以外的语言。

我的理解正确吗?如果没有,我想要详细的解释或任何解释它的来源。

首先,检查你的sklearn版本。我觉得你使用的是旧版本的 sklearn。您对 CountVectorizer 的解释不正确。它没有统计语料库中不同词的数量,至少当前版本没有。

根据 docs of CountVectorizer, you need to pass analyzer='word' to make the word count. In the latest version of sklearn, CharNGramAnalyzer is deprecated and now merged with CountVectorizer. Just do analyzer='char' to replicate CharNGramAnalyzer. To verify this check http://scikit-learn.org/stable/modules/classes.html#module-sklearn.feature_extraction.text CharNGramAnalyzer

没有条目