Tôi đã cài đặt python 2.7, gumpy 1.9.0, scipy 0.15.1 và scikit-learn 0.15.2. Bây giờ khi tôi làm như sau trong python:CountVectorizer không in từ vựng
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.
Trên thực tế nó nên đã in như sau:
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
Đoạn mã trên là từ blog: http://blog.christianperone.com/?p=1589
Ông có thể vui lòng giúp đỡ tôi là lý do tại sao tôi nhận được một lỗi như vậy. Vì từ vựng không được lập chỉ mục đúng cách nên tôi không thể tiến lên trong việc hiểu khái niệm về TF-IDF. Tôi là một newbie cho python để giúp đỡ bất kỳ sẽ được đánh giá cao.
Arc.
Có. Cảm ơn. Tôi sẽ thử sử dụng vỏ ipython để tôi không bỏ lỡ việc hoàn thành tab đó. Tôi có vỏ ipython không bao giờ biết điều này. Cảm ơn vì thông tin. – Archana
Ở trên tôi cũng hỏi làm thế nào đến từ dừng của tôi = Không có trong CountVectorize mà không phải là trường hợp. – Archana
Giá trị mặc định cho stop_words là None. Bạn có thể tạo vectơ như thế này: vectorizer = CountVectorizer (stop_words = 'english') nếu bạn muốn sử dụng các từ dừng tiếng Anh được xây dựng. –