Sklearn CountVectorizer를 'word'와 'char'분석기와 함께 어떻게 사용합니까? http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.htmlSklearn CountVectorizer를 'word'및 'char'분석기와 함께 어떻게 사용합니까? - python
단어 나 문자로 텍스트 기능을 추출 할 수 있지만 어떻게 charword_vectorizer
을 만들 수 있습니까? 벡터 라이 제이션을 결합하는 방법이 있습니까? 또는 하나 이상의 분석기를 사용합니까?
>>> from sklearn.feature_extraction.text import CountVectorizer
>>> word_vectorizer = CountVectorizer(analyzer='word', ngram_range=(1, 2), min_df=1)
>>> char_vectorizer = CountVectorizer(analyzer='char', ngram_range=(1, 2), min_df=1)
>>> x = ['this is a foo bar', 'you are a foo bar black sheep']
>>> word_vectorizer.fit_transform(x)
<2x15 sparse matrix of type '<type 'numpy.int64'>'
with 18 stored elements in Compressed Sparse Column format>
>>> char_vectorizer.fit_transform(x)
<2x47 sparse matrix of type '<type 'numpy.int64'>'
with 64 stored elements in Compressed Sparse Column format>
>>> char_vectorizer.get_feature_names()
[u' ', u' a', u' b', u' f', u' i', u' s', u'a', u'a ', u'ac', u'ar', u'b', u'ba', u'bl', u'c', u'ck', u'e', u'e ', u'ee', u'ep', u'f', u'fo', u'h', u'he', u'hi', u'i', u'is', u'k', u'k ', u'l', u'la', u'o', u'o ', u'oo', u'ou', u'p', u'r', u'r ', u're', u's', u's ', u'sh', u't', u'th', u'u', u'u ', u'y', u'yo']
>>> word_vectorizer.get_feature_names()
[u'are', u'are foo', u'bar', u'bar black', u'black', u'black sheep', u'foo', u'foo bar', u'is', u'is foo', u'sheep', u'this', u'this is', u'you', u'you are']
용의자, 'r'\ w {3,}'은 무엇을 의미합니까? '[a-zA-Z0-9_]'와 같은가요? – alvas
@alvas :'\ w'는'[a-zA-Z0-9_]'입니다; '{3,} '는 "3 개 이상"을 의미하므로 짧은 토큰을 건너 뜁니다. 토큰을 캡처하기 위해 여러 RE를 시험해볼 수도 있습니다. 이것은 나의 기준선 중 하나입니다. –