小编Arc*_*kla的帖子

在 Scikit-Learn 特征提取中合并 CountVectorizer

我是 scikit-learn 的新手,需要一些帮助来完成我一直在做的事情。

我正在尝试使用多项式朴素贝叶斯分类对两种类型的文档(例如 A 型和 B 型)进行分类。为了获取这些文档的术语计数,我在 sklearn.feature_extraction.text 中使用 CountVectorizer 类。

问题在于,两种类型的文档需要不同的正则表达式来提取标记(CountVectorization 的 token_pattern 参数)。我似乎找不到一种方法来首先加载类型 A 的训练文档,然后加载类型 B 的训练文档。是否可以执行以下操作:

vecA = CountVectorizer(token_pattern="[a-zA-Z]+", ...)
vecA.fit(list_of_type_A_document_content)
...
vecB = CountVectorizer(token_pattern="[a-zA-Z0-9]+", ...)
vecB.fit(list_of_type_B_document_content)
...
# Somehow merge the two vectorizers results and get the final sparse matrix
Run Code Online (Sandbox Code Playgroud)

python feature-extraction scikit-learn

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

标签 统计

feature-extraction ×1

python ×1

scikit-learn ×1