【发布时间】:2016-08-15 11:50:59
【问题描述】:
我在将 sklearn CountVectorizer 与包含单词“one”的文档一起使用时遇到了问题。我发现当文档仅包含 POS 标签 CD(基数)的单词时会发生错误。以下文档都导致空词汇错误: ['一二'] ['一百']
ngram_code=1
cv = CountVectorizer(stop_words='english', analyzer='word', lowercase=True,\
token_pattern="[\w']+", ngram_range=(ngram_code, ngram_code))
cv_array = cv.fit_transform(['one', 'two'])
得到错误: ValueError:空词汇;也许文档只包含停用词
以下不会导致错误,因为(我认为)基数词与其他词混合: ['一','二','人']
有趣的是,在这种情况下,词汇表中只添加了“人”,没有添加“一”、“二”:
cv_array = cv.fit_transform(['one', 'two', 'people'])
cv.vocabulary_
Out[143]: {'people': 0}
作为单个 word 文档的另一个示例,['hello'] 可以正常工作,因为它不是基数:
cv_array = cv.fit_transform(['hello'])
cv.vocabulary_
Out[147]: {'hello': 0}
由于像“一”、“二”这样的词不是停用词,我希望它们由 CountVectorizer 处理。我该如何处理这些词?
补充:“系统”这个词我也遇到了同样的错误。为什么这个词会出错?
cv_array = cv.fit_transform(['system'])
ValueError:空词汇;也许文档只包含停用词
【问题讨论】:
标签: scikit-learn