2017-09-18 140 views
0

識別相干性值I嘗試運行LDA型號N傳遞LDA對象到get_coherence()它表示錯誤錯誤而從LDA模型

x.get_coherence()

***類型錯誤: DIAGS()至少需要2個參數(2給出)

我的代碼: -

iModel = models.ldamodel.LdaModel(語料庫=語料庫,id2word =字典,NUM_TOPICS = I,傳遞= 10)

ldalist.append(iModel)

X = CoherenceModel(型號= iModel,文本= tokenizedTexts,字典=字典,相干=相干性)

cohValue = x.get_coherence()

回答

1

u_mass相干性可以沒有原始文本計算。

該文本只是「非矢量化」的語料庫。

你變換胼成這樣一大堆單詞的列表,然後才能使用它的連貫性:

texts = [[dictionary[word_id] for word_id, freq in doc] for doc in corpus] 

然後建立一致性模型,並得到結果:

u_mass = models.CoherenceModel(model=topic_model, corpus=corpus, dictionary=dictionary, coherence='u_mass') 
u_mass_coh = u_mass.get_coherence() 

c_v = models.CoherenceModel(model=topic_model, texts=texts, corpus=corpus, dictionary=dictionary, coherence='c_v') 
c_v_coh = c_v.get_coherence() 

c_uci = models.CoherenceModel(model=topic_model, texts=texts, corpus=corpus, dictionary=dictionary, coherence='c_uci') 
c_uci_coh = c_uci.get_coherence() 

c_npmi = models.CoherenceModel(model=topic_model, texts=texts, corpus=corpus, dictionary=dictionary, coherence='c_npmi') 
c_npmi_coh = c_npmi.get_coherence() 
+0

文本= [[字典[word_id] for word_id,freq in doc] for doc in corpus] text [[u'mini',u'major',u'inflammatory',u'review',u'bowl',u'disease' ,u'involve',u'virulence',u'aiec',u'the'],[u'interaction',u'patient',u'herb',u'ibd',u'drug',u'老人','你好',你'關注']] topic_model,文本=文本,胼=語料庫,字典=字典,相干= 'c_v')get_coherence() ***類型錯誤:DIAGS()至少需要2個參數(2給出) – user3480223