lda

How to print the LDA topics models from gensim? Python

匿名 (未验证) 提交于 2019-12-03 01:06:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Using gensim I was able to extract topics from a set of documents in LSA but how do I access the topics generated from the LDA models? When printing the lda.print_topics(10) the code gave the following error because print_topics() return a NoneType : Traceback (most recent call last): File "/home/alvas/workspace/XLINGTOP/xlingtop.py", line 93, in for top in lda.print_topics(2): TypeError: 'NoneType' object is not iterable The code: from gensim import corpora, models, similarities from gensim.models import hdpmodel, ldamodel from itertools

value toDF is not a member of org.apache.spark.rdd.RDD[(Long, org.apache.spark.ml.linalg.Vector)]

匿名 (未验证) 提交于 2019-12-03 01:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Am getting a compilation error converting the pre-LDA transformation to a data frame using SCALA in SPARK 2.0. The specific code that is throwing an error is as per below: val documents = PreLDAmodel.transform(mp_listing_lda_df) .select("docId","features") .rdd .map{ case Row(row_num: Long, features: MLVector) => (row_num, features) } .toDF() The complete compilation error is: Error:(132, 8) value toDF is not a member of org.apache.spark.rdd.RDD[(Long, org.apache.spark.ml.linalg.Vector)] possible cause: maybe a semicolon is missing before

From TF-IDF to LDA clustering in spark, pyspark

匿名 (未验证) 提交于 2019-12-03 00:59:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to cluster tweets stored in the format key,listofwords My first step has been to extract TF-IDF values for the list of words using dataframe with dbURL = "hdfs://pathtodir" file = sc.textFile(dbURL) #Define data frame schema fields = [StructField('key',StringType(),False),StructField('content',StringType(),False)] schema = StructType(fields) #Data in format <key>,<listofwords> file_temp = file.map(lambda l : l.split(",")) file_df = sqlContext.createDataFrame(file_temp, schema) #Extract TF-IDF From https://spark.apache.org/docs/1

LDA实践3(NLP)

匿名 (未验证) 提交于 2019-12-03 00:37:01
# !/usr/bin/python # -*- coding:utf-8 -*- import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import lda import lda.datasets from pprint import pprint if __name__ == "__main__": # document-term matrix X = lda.datasets.load_reuters() print("type(X): {}".format(type(X))) print("shape: {}\n".format(X.shape)) print(X[:10, :10]) # the vocab vocab = lda.datasets.load_reuters_vocab() print("type(vocab): {}".format(type(vocab))) print("len(vocab): {}\n".format(len(vocab))) print(vocab[:10]) # titles for each story titles = lda.datasets.load_reuters_titles() print("type(titles):

用scikit-learn进行LDA降维

匿名 (未验证) 提交于 2019-12-02 23:49:02
    在 线性判别分析LDA原理总结 中,我们对LDA降维的原理做了总结,这里我们就对scikit-learn中LDA的降维使用做一个总结。     在scikit-learn中, LDA类是sklearn.discriminant_analysis.LinearDiscriminantAnalysis。那既可以用于分类又可以用于降维。当然,应用场景最多的还是降维。和PCA类似,LDA降维基本也不用调参,只需要指定降维到的维数即可。     我们这里对LinearDiscriminantAnalysis类的参数做一个基本的总结。     1) solver shrinkage 进行正则化。默认值是svd     2) shrinkage :正则化参数,可以增强LDA分类的泛化能力。如果仅仅只是为了降维,则一般可以忽略这个参数。默认是None,即不进行正则化。可以选择"auto",让算法自己决定是否正则化。当然我们也可以选择不同的[0,1]之间的值进行交叉验证调参。注意shrinkage只在solver为最小二乘"lsqr"和特征分解"eigen"时有效。     3) priors     4) n_components :即我们进行LDA降维时降到的维数。在降维时需要输入这个参数。注意只能为[1,类别数-1)范围之间的整数。如果我们不是用于降维,则这个值可以用默认的None。

常用数据挖掘算法-聚类

匿名 (未验证) 提交于 2019-12-02 23:38:02
概述 数据挖掘常又被称为价值发现或者是数据勘探,一般是指从大量的、不完全的、有噪声的、模糊的、随机的实际应用数据中,提取隐含在其中的,人们事先不知道的、但又是潜在有用的信息和知识的过程。它是一种大量数据的高级处理方式。 常用的数据挖掘算法分为四大类:聚类、分类、关联以及推荐算法。另外还有一个预处理:降维算法 聚类算法 聚类是在一群未知类别标号的样本上,用某种算法将他们分成若干类别,这是一种无监督学习。其主要研究数据间逻辑上或物理上的相互关系。由聚类所组成的簇是一组数据对象的集合,这些对象与同一簇中的对象彼此类似,与其他簇中的对象相异。其分析结果不仅可以揭示数据间的内在联系与区别,还可以为进一步的数据分析与知识发现提供重要依据。聚类算法的聚类效果如图所示 常用的聚类算法由k-means聚类算法、Canopy 聚类算法、FCM(Fuzzy C-Means,模糊C 均值)聚类算法、DBSCAN(Density-Based Spatial Clustering of Applications with Noise,具有噪声的基于密度的聚类方法)聚类算法、LDA(Latent Dirichlet Allocation,隐含狄利克雷分配)算法、层次聚类算法、基于EM(Expectation-Maximization,最大期望)的聚类算法等。以下将对上述聚类算法从算法的简介

lda主题模型python实现篇

匿名 (未验证) 提交于 2019-12-02 22:54:36
个人博客地址: http://xurui.club/ 最近在做一个动因分析的项目,自然想到了主题模型LDA。这次先把模型流程说下,原理后面再讲。 lda实现有很多开源库,这里用的是gensim. 大概说下文本的样子,LDA是无监督模型,也就是说不需要标签,只要传入文本就好。LDA要学习文档-主题分布和主题-词分布,所以我们把一个人的数据join在一起作为一条文档。对文档进行分词,使用的jieba分词工具包。注意,这里要做去停用词处理,包括标点和一些没用的词,如“呵呵”,“哈哈”。做项目时,第一版没有去无用词,最后提出的主题都是“你”“我”“他”“你好”这样的东西,去掉之后可以较好提高结果质量。 即将所有文档数表示成m*n的矩阵D,m表示有m篇文档,n表示这篇文档有n个词,n不定长。 用gensim.corpora.Dictionary包 这个包讲下吧 from gensim.corpora import Dictionary text = [['我', '想吃', '大龙虾', '和', '烤猪蹄']] dictionary = Dictionary(text) print ((dictionary)) doc = dictionary.doc2bow([ '我' , '想吃' , '大龙虾' , '和' , '我' , '你' , '烤猪蹄' ]) print (doc) ###

Python之LDA主题模型算法应用

匿名 (未验证) 提交于 2019-12-02 22:51:30
版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 ( Creative Commons ) 在这篇文章中,我将介绍用于Latent Dirichlet Allocation(LDA)的lda Python包的安装和基本用法。我不会在这篇文章中介绍该方法的理论基础。然而,这个模型的主要参考,Blei etal 2003可以在线免费获得,我认为将语料库(文档集)中的文档分配给基于单词矢量的潜在(隐藏)主题的主要思想是相当容易理解的而这个例子(来自lda)将有助于巩固我们对LDA模型的理解。那么,让我们开始...... 安装lda 在之前的帖子中,我介绍了使用 pip virtualenwrapper 安装Python包,请参阅帖子了解更多详细信息: 在Ubuntu 14.04上安装Python包 在Ubuntu 14.04上的virtualenv和virtualenvwrapper 简而言之,我将提到两种方法: 方法1 : 我将以用户身份安装lda $ pip install --user lda 这也将安装所需的 pbr 包。现在我将 在一个设置中提供lda,其中包含我之前安装的所有其他软件包(再次参见上文)。使用此方法,您应该在安装后得到类似的内容: $ pip show lda --- 名称:lda 版本:0.3.2 位置:/home

Can we use a self made corpus for training for LDA using gensim?

别等时光非礼了梦想. 提交于 2019-12-02 21:06:01
I have to apply LDA (Latent Dirichlet Allocation) to get the possible topics from a data base of 20,000 documents that I collected. How can I use these documents rather than the other corpus available like the Brown Corpus or English Wikipedia as training corpus ? You can refer this page. After going through the documentation of the Gensim package, I found out that there are total 4 ways of transforming a text repository into a corpus. There are total 4 formats for the corpus: Market Matrix (.mm) SVM Light (.svmlight) Blie Format (.lad-c) Low Format (.low) In this problem, as mentioned above

Extract document-topic matrix from Pyspark LDA Model

江枫思渺然 提交于 2019-12-02 18:18:53
I have successfully trained an LDA model in spark, via the Python API: from pyspark.mllib.clustering import LDA model=LDA.train(corpus,k=10) This works completely fine, but I now need the document -topic matrix for the LDA model, but as far as I can tell all I can get is the word -topic, using model.topicsMatrix() . Is there some way to get the document-topic matrix from the LDA model, and if not, is there an alternative method (other than implementing LDA from scratch) in Spark to run an LDA model that will give me the result I need? EDIT: After digging around a bit, I found the documentation