0

나는 vocabulary_.get을 사용하는데 의문의 여지가있다. 코드는 다음과 같다. 아래에서 볼 수 있듯이 특정 단어의 발생 횟수를 얻기 위해 컴퓨터 학습 연습 중 하나에서 CountVectorizer를 사용했습니다.sklearn CountVectorizer

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')) 

출력 :

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 '바이블'을 보여줍니다 이유 없음을 보여줍니다 없다는 것입니다. vocabulary_.get은 자본 벡터와 잘 작동하지 않습니까?

답변

1

CountVectorizer이 매개 변수 lowercase 소요 그 문서 here에 명시된 바와 같이 True 기본값 : False에 다르게 소문자와 대문자 치료하려면 것을

lowercase : boolean, True by default 
    Convert all characters to lowercase before tokenizing. 

변화.