本文整理汇总了Python中sklearn.decomposition.LatentDirichletAllocation.get_params方法的典型用法代码示例。如果您正苦于以下问题:Python LatentDirichletAllocation.get_params方法的具体用法?Python LatentDirichletAllocation.get_params怎么用?Python LatentDirichletAllocation.get_params使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition.LatentDirichletAllocation
的用法示例。
在下文中一共展示了LatentDirichletAllocation.get_params方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: applyLDA2
# 需要导入模块: from sklearn.decomposition import LatentDirichletAllocation [as 别名]
# 或者: from sklearn.decomposition.LatentDirichletAllocation import get_params [as 别名]
def applyLDA2(self, number_of_clusters, country_specific_tweets):
train, feature_names = self.extractFeatures(country_specific_tweets,False)
name = "lda"
if self.results:
print("Fitting LDA model with tfidf", end= " - ")
t0 = time()
lda = LatentDirichletAllocation(n_topics=number_of_clusters, max_iter=5,
learning_method='online', learning_offset=50.,
random_state=0)
lda.fit(train)
if self.results:
print("done in %0.3fs." % (time() - t0))
parameters = lda.get_params()
topics = lda.components_
doc_topic = lda.transform(train)
top10, labels = self.printTopicCluster(topics, doc_topic, feature_names)
labels = numpy.asarray(labels)
if self.results:
print("Silhouette Coefficient {0}: {1}".format(name, metrics.silhouette_score(train, labels)))
return name, parameters, top10, labels
示例2: LatentDirichletAllocation
# 需要导入模块: from sklearn.decomposition import LatentDirichletAllocation [as 别名]
# 或者: from sklearn.decomposition.LatentDirichletAllocation import get_params [as 别名]
print "number of docs: %d" %A_tfidf_sp.shape[0]
print "dictionary size: %d" %A_tfidf_sp.shape[1]
#tf-idf dictionary
tfidf_dict = tfidf.get_feature_names()
#fit LDA model
print "Fitting LDA model..."
lda_vb = LatentDirichletAllocation(n_topics = num_topics, max_iter=10, learning_method='online', batch_size = 512, random_state=0, n_jobs=-1)
tic = time()
lda_vb.fit(A_tfidf_sp) #online VB
toc = time()
print "elapsed time: %.4f sec" %(toc - tic)
print "LDA params"
print lda_vb.get_params()
print "number of EM iter: %d" % lda_vb.n_batch_iter_
print "number of dataset sweeps: %d" % lda_vb.n_iter_
#topic matrix W: K x V
#components[i,j]: topic i, word j
topics = lda_vb.components_
f = plt.figure()
plt.matshow(topics, cmap = 'gray')
plt.gca().set_aspect('auto')
plt.title('learned topic matrix')
plt.ylabel('topics')
plt.xlabel('dictionary')
plt.show()