首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sklearn CountVectorizer

sklearn CountVectorizer
EN

Stack Overflow用户
提问于 2017-10-09 23:39:44
回答 2查看 560关注 0票数 0

我对使用vocabulary_.get有疑问,代码如下。如下所示,我在一个机器学习练习中使用了CountVectorizer,以获取特定单词的出现次数。

代码语言:javascript
复制
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
s1 = 'KJ YOU WILL BE FINE'
s2 = 'ABHI IS MY BESTIE'
s3 = 'sam is my bestie'
frnd_list = [s1,s2,s3]
bag_of_words = vectorizer.fit(frnd_list)
bag_of_words = vectorizer.transform(frnd_list)
print(bag_of_words)
# To get the feature word number from word 
#for eg:
print(vectorizer.vocabulary_.get('bestie'))
print(vectorizer.vocabulary_.get('BESTIE'))

输出:

代码语言:javascript
复制
Bag_of_words is :
(0, 1)  1
(0, 3)  1
(0, 5)  1
(0, 8)  1
(0, 9)  1
(1, 0)  1
(1, 2)  1
(1, 4)  1
(1, 6)  1
(2, 2)  1
(2, 4)  1
(2, 6)  1
(2, 7)  1

'bestie' has  feature number:
 2
'BESTIE' has feature number:
 None

因此,我怀疑为什么'bistie‘显示正确的特征数,即2,而'BESTIE’显示没有。vocabulary_.get不能很好地处理资本向量吗?

EN

回答 2

Stack Overflow用户

发布于 2017-10-10 01:00:47

CountVectorizer采用缺省为True的参数lowercase,如文档here中所述

小写:布尔值,默认情况下,在标记化之前将所有字符转换为小写。

如果您想区分小写和大写,请将其更改为False

票数 2
EN

Stack Overflow用户

发布于 2018-07-15 05:53:19

countvectorizer接受一个参数"lowercase“,默认情况下它的值为true

如果我们想区分大小写字母,那么设置lowercase=False

有关详细信息,请单击此处http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46650204

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档