【发布时间】:2019-03-09 15:22:07
【问题描述】:
我正在处理文本分类中的一个问题,如果以这种格式 "word" 找到一个单词,它的重要性将不同于以这种格式 word 找到的单词> 所以我尝试了这段代码
import re
from sklearn.feature_extraction.text import CountVectorizer
sent1 = "The cat sat on my \"face\" face"
sent2 = "The dog sat on my bed"
content = [sent1,sent2]
vectorizer = CountVectorizer(token_pattern=r"(?u)\b\w\w+\b|!|\?|\"|\'")
vectorizer.fit(content)
print (vectorizer.get_feature_names())
结果是
['"', 'bed', 'cat', 'dog', 'face', 'my', 'on', 'sat', 'the']
我希望它在哪里
['bed', 'cat', 'dog', 'face','"face"' 'my', 'on', 'sat', 'the']
【问题讨论】:
-
这是一个标记化问题。修复
token_pattern以捕获双引号的情况,或提供tokeniser可调用CountVectorizer
标签: python text-classification tf-idf