2015-03-06 6 views
10

मैंने पायथन 2.7, numpy 1.9.0, scipy 0.15.1 और scikit-learn 0.15.2 स्थापित किया है। अब जब मैं अजगर में निम्नलिखित है:CountVectorizer शब्दावली मुद्रित नहीं करता

train_set = ("The sky is blue.", "The sun is bright.") 
test_set = ("The sun in the sky is bright.", 
"We can see the shining sun, the bright sun.") 

from sklearn.feature_extraction.text import CountVectorizer 
vectorizer = CountVectorizer() 

print vectorizer 


    CountVectorizer(analyzer=u'word', binary=False, charset=None, 
    charset_error=None, decode_error=u'strict', 
    dtype=<type 'numpy.int64'>, encoding=u'utf-8', input=u'content', 
    lowercase=True, max_df=1.0, max_features=None, min_df=1, 
    ngram_range=(1, 1), preprocessor=None, stop_words=None, 
    strip_accents=None, token_pattern=u'(?u)\\b\\w\\w+\\b', 
    tokenizer=None, vocabulary=None) 

    vectorizer.fit_transform(train_set) 
    print vectorizer.vocabulary 

    None. 

वास्तव में यह मुद्रित किया जाना चाहिए था निम्नलिखित: http://blog.christianperone.com/?p=1589

आप कृपया मदद कर सका:

CountVectorizer(analyzer__min_n=1, 
analyzer__stop_words=set(['all', 'six', 'less', 'being', 'indeed', 'over',  
'move', 'anyway', 'four', 'not', 'own', 'through', 'yourselves', (...) --->  
For count vectorizer 

{'blue': 0, 'sun': 1, 'bright': 2, 'sky': 3} ---> for vocabulary 

ऊपर कोड ब्लॉग से कर रहे हैं मुझे इस तरह की त्रुटि क्यों मिलती है। चूंकि शब्दावली को ठीक से अनुक्रमित नहीं किया गया है, इसलिए मैं टीएफ-आईडीएफ की अवधारणा को समझने में आगे बढ़ने में सक्षम नहीं हूं। मैं अजगर के लिए नौसिखिया हूँ इसलिए किसी भी मदद की सराहना की जाएगी।

आर्क।

उत्तर

13

आप एक अंडरस्कोर याद कर रहे हैं, इस तरह का प्रयास करें:

from sklearn.feature_extraction.text import CountVectorizer 
train_set = ("The sky is blue.", "The sun is bright.") 
test_set = ("The sun in the sky is bright.", 
    "We can see the shining sun, the bright sun.") 

vectorizer = CountVectorizer(stop_words='english') 
document_term_matrix = vectorizer.fit_transform(train_set) 
print vectorizer.vocabulary_ 
# {u'blue': 0, u'sun': 3, u'bright': 1, u'sky': 2} 

आप IPython खोल का उपयोग करते हैं, तो आप टैब पूरा होने का उपयोग कर सकते हैं, और आप आसान तरीके और वस्तुओं की विशेषताओं पा सकते हैं।

+0

हां। धन्यवाद। मैं ipython खोल का उपयोग करने की कोशिश करूंगा ताकि मुझे इस तरह के टैब पूर्ण होने पर याद न हो। मेरे पास ipython shell कभी नहीं जानता था। जानकारी के लिए धन्यवाद। – Archana

+0

उपर्युक्त में मैंने यह भी पूछा कि मेरे स्टॉप शब्द कैसे आते हैं = काउंटर वेक्टरिज़ में कोई भी नहीं जो मामला नहीं होना चाहिए। – Archana

+1

stop_words के लिए डिफ़ॉल्ट मान कोई नहीं है। आप इस तरह वेक्टरइज़र बना सकते हैं: vectorizer = countVectorizer (stop_words = 'english') यदि आप अंग्रेजी स्टॉप शब्दों में निर्मित का उपयोग करना चाहते हैं। –

2

vectorizer.get_feature_names() विधि का उपयोग करने का प्रयास करें। यह कॉलम नाम document_term_matrix में दिखाई देने वाले क्रम में देता है।

from sklearn.feature_extraction.text import CountVectorizer 
train_set = ("The sky is blue.", "The sun is bright.") 
test_set = ("The sun in the sky is bright.", 
    "We can see the shining sun, the bright sun.") 

vectorizer = CountVectorizer(stop_words='english') 
document_term_matrix = vectorizer.fit_transform(train_set) 
vectorizer.get_feature_names() 
#> ['blue', 'bright', 'sky', 'sun'] 
संबंधित मुद्दे