Last active
June 19, 2018 02:35
-
-
Save ken333135/fc133f6ae074b2746d7c13e75e7c7d1a to your computer and use it in GitHub Desktop.
Get Top words for each class (multi-class text classification)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_top_words(class,n): | |
ind = np.argpartition(list(vect_data.loc[class]),-n)[-n:] | |
top_words=[] | |
for index in ind: | |
top_words.append([list(vect.vocabulary_.keys())[list(vect.vocabulary_.values()).index(index)], | |
list(vect_data.loc[code])[index]]) | |
return top_words | |
#test the function on class 'ACON'. Grab the top 6 words | |
find_top_words('ACON',6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment