Skip to content

Instantly share code, notes, and snippets.

@ken333135
Last active June 19, 2018 02:35
Show Gist options
  • Save ken333135/fc133f6ae074b2746d7c13e75e7c7d1a to your computer and use it in GitHub Desktop.
Save ken333135/fc133f6ae074b2746d7c13e75e7c7d1a to your computer and use it in GitHub Desktop.
Get Top words for each class (multi-class text classification)
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