Wie erhalte ich mit Sklearn eine Menge Wörter und die Häufigkeit von Begriffen im Textformat?Python

Python-Programme
Guest
 Wie erhalte ich mit Sklearn eine Menge Wörter und die Häufigkeit von Begriffen im Textformat?

Post by Guest »

Ich möchte die Liste der Wörter (d. h. eine Menge Wörter) für jedes Dokument in einem Coprus und ihre jeweilige Begriffshäufigkeit (im Textformat) mit Sklearns CountVectorizer ausdrucken. Wie könnte ich das erreichen?
Hier ist mein Code:

Code: Select all

from sklearn.feature_extraction.text import CountVectorizer

#instantiate vectorizer
vectorizer=CountVectorizer()

#Document creation
document1='this is a sunny day';document2= 'today is a very very very pleasant day and we have fun fun fun';document3= 'this is an amazin experience'

#list
list_of_words= [document1,document2,document3]

#bag of words
bag_of_words = vectorizer.fit(list_of_words)

#verify vocabulary of repeated word
print (vectorizer.vocabulary_.get('very'))

print (vectorizer.vocabulary_.get('fun'))

#transform
bag_of_words=vectorizer.transform(list_of_words)

print(bag_of_words)>>>>
(0, 3) 1 (0, 7) 1 (0, 9) 1 (0, 10) 1 (1, 2) 1 (1, 3) 1 (1, 5) 3 (1, 6) 1 (1, 7) 1 (1, 8) 1 (1, 11) 1 (1, 12) 3 (1, 13) 1 (2, 0) 1 (2, 1) 1 (2, 4) 1 (2, 7) 1 (2, 10) 1

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post