- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用朴素贝叶斯和 countVectorizer 进行文本分类来对方言进行分类。我读过一篇研究论文,作者使用了以下组合:
bigrams + trigrams + word-marks vocabulary
他在这里所说的词标是指特定于某种方言的词。
如何调整 countVectorizer 中的这些参数?
这些是文字标记的示例,但这不是我所拥有的,因为我的是阿拉伯语。所以我翻译了它们。
word_marks=['love', 'funny', 'happy', 'amazing']
它们用于对文本进行分类。
此外,在这篇文章中: Understanding the `ngram_range` argument in a CountVectorizer in sklearn
有这样的答案:
>>> v = CountVectorizer(ngram_range=(1, 2), vocabulary={"keeps", "keeps the"})
>>> v.fit_transform(["an apple a day keeps the doctor away"]).toarray()
array([[1, 1]]) # unigram and bigram found
我无法理解输出,[1,1] 这里是什么意思?他是如何将 ngram 与词汇结合使用的呢?两者不是互相排斥的吗?
最佳答案
您想要使用 n_gram 范围参数来使用二元组和三元组。在您的情况下,它将是 CountVectorizer(ngram_range=(1, 3))。
查看已接受的答案 to this question了解更多详情。
请为您的问题的其他部分提供“文字标记”的示例。
您可能需要运行 CountVectorizer 两次 - 一次针对 n-gram,一次针对您的自定义字标词汇表。然后,您可以连接两个 CountVectorizer 的两个输出,以获得 n 元语法计数和自定义词汇计数的单个功能集。上述问题的答案还解释了如何为 CountVectorizer 的第二次使用指定自定义词汇表。
这是一个SO answer关于连接数组
关于machine-learning - 如何在 countVectorizer 中使用二元组 + 三元组 + 字标词汇?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56083449/
我是一名优秀的程序员,十分优秀!