'I'

2015-10-21 10 views
5

अनदेखा करने वाले काउंटर वेक्टरोरिज़र सर्वनाम "I" को अनदेखा करते हुए sklearn में countVectorizer क्यों है?'I'

ngram_vectorizer = CountVectorizer(analyzer = "word", ngram_range = (2,2), min_df = 1) 
ngram_vectorizer.fit_transform(['HE GAVE IT TO I']) 
<1x3 sparse matrix of type '<class 'numpy.int64'>' 
ngram_vectorizer.get_feature_names() 
['gave it', 'he gave', 'it to'] 

उत्तर

7

डिफ़ॉल्ट टोकनेज़र केवल 2-वर्ण (या अधिक) शब्दों को मानता है।

आप अपने token_pattern को CountVectorizer पर उचित पास करके इस व्यवहार को बदल सकते हैं।

डिफ़ॉल्ट पैटर्न है (the signature in the docs देखें):

'token_pattern': u'(?u)\\b\\w\\w+\\b' 

आप एक CountVectorizer कि डिफ़ॉल्ट बदलकर एक अक्षर का शब्द ड्रॉप नहीं है प्राप्त कर सकते हैं, उदाहरण के लिए:

from sklearn.feature_extraction.text import CountVectorizer 
ngram_vectorizer = CountVectorizer(analyzer="word", ngram_range=(2,2), 
            token_pattern=u"(?u)\\b\\w+\\b",min_df=1) 
ngram_vectorizer.fit_transform(['HE GAVE IT TO I']) 
print(ngram_vectorizer.get_feature_names()) 

कौन देता है :

['gave it', 'he gave', 'it to', 'to i'] 
संबंधित मुद्दे