코퍼스를 정의하고 CountVectorizer() 객체를 생성합니다.

    코드 10-2 코퍼스에 카운터 벡터 적용

    from sklearn.feature_extraction.text import CountVectorizer
    corpus = [
        'This is last chance.',
        'and if you do not have this chance.',
        'you will never get any chance.',
        'will you do get this one?',
        'please, get this chance',
    ]
    vect = CountVectorizer()
    vect.fit(corpus)
    vect.vocabulary_

    다음은 코퍼스에 카운터 벡터를 적용한 결과입니다.

    {'this': 13,
     'is': 7,
     'last': 8,
     'chance': 2,
     'and': 0,
     'if': 6,
     'you': 15,
     'do': 3,
     'not': 10,
     'have': 5,
     'will': 14,
     'never': 9,
     'get': 4,
     'any': 1,
     'one': 11,
     'please': 12}
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.