Last active
April 7, 2018 05:53
-
-
Save smsubrahmannian/a6ff56fcf5ff12657e96b64e40b8c994 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from gensim import models,corpora | |
import pyLDAvis.gensim | |
# lda_final is the lda model built with 12 topics | |
# vis is the pyLDAvis object | |
vis = pyLDAvis.gensim.prepare(lda_final, doc_term_matrix, dictionary,sort_topics=False) | |
def get_relevant_words(vis,lam=0.3,topn=10): | |
a = vis.topic_info | |
a['finalscore'] = a['logprob']*lam+(1-lam)*a['loglift'] | |
a = a.loc[:,['Category','Term','finalscore']].groupby(['Category'])\ | |
.apply(lambda x: x.sort_values(by='finalscore',ascending=False).head(topn)) | |
a = a.loc[:,'Term'].reset_index().loc[:,['Category','Term']] | |
a = a[a['Category']!='Default'] | |
return a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment