如何在Scikit-Learn文本CountVectorizer或TfidfVectorizer中保留标点符号? [英] How to preserve punctuation marks in Scikit-Learn text CountVectorizer or TfidfVectorizer?

查看:371
本文介绍了如何在Scikit-Learn文本CountVectorizer或TfidfVectorizer中保留标点符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否可以使用Scikit-Learn中的文本CountVectorizer或TfidfVectorizer参数从文本文档中保留!,?,和'的标点符号?

Is there any way for me to preserve punctuation marks of !, ?, " and ' from my text documents using text CountVectorizer or TfidfVectorizer parameters in Scikit-Learn?

先谢谢了.

推荐答案

在实例化矢量化程序时,应自定义token_pattern参数.例如:

You should customize the token_pattern parameter when you instantiate the vectorizer. For example:

vent = CountVectorizer(token_pattern=r"(?u)\b\w\w+\b|!|\?|\"|\'")

这篇关于如何在Scikit-Learn文本CountVectorizer或TfidfVectorizer中保留标点符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆