lda

Spark 2.1.1: How to predict topics in unseen documents on already trained LDA model in Spark 2.1.1?

谁说胖子不能爱 提交于 2019-12-31 04:39:08
问题 I am training an LDA model in pyspark (spark 2.1.1) on a customers review dataset. Now based on that model I want to predict the topics in the new unseen text. I am using the following code to make the model from pyspark import SparkConf, SparkContext from pyspark.sql import SparkSession from pyspark.sql import SQLContext, Row from pyspark.ml.feature import CountVectorizer from pyspark.ml.feature import HashingTF, IDF, Tokenizer, CountVectorizer, StopWordsRemover from pyspark.mllib.clustering

Use scikit-learn TfIdf with gensim LDA

自作多情 提交于 2019-12-29 06:18:09
问题 I've used various versions of TFIDF in scikit learn to model some text data. vectorizer = TfidfVectorizer(min_df=1,stop_words='english') The resulting data X is in this format: <rowsxcolumns sparse matrix of type '<type 'numpy.float64'>' with xyz stored elements in Compressed Sparse Row format> I wanted to experiment with LDA as a way to do reduce dimensionality of my sparse matrix. Is there a simple way to feed the NumPy sparse matrix X into a gensim LDA model? lda = models.ldamodel.LdaModel

Linear discriminant analysis variable importance

浪尽此生 提交于 2019-12-25 02:25:31
问题 Using the R MASS package to do a linear discriminant analysis, is there a way to get a measure of variable importance? Library(MASS) ### import data and do some preprocessing fit <- lda(cat~., data=train) I have is a data set with about 20 measurements to predict a binary category. But the measurements are hard to obtain so I want to reduce the number of measurements to the most influential. When using rpart or randomForests I can get a list of variable importance, or a gimi decrease stat

How to get all the keywords based on topic using topic modeling?

半腔热情 提交于 2019-12-25 02:19:41
问题 I'm trying to segregate the topics using lda's topic modeling. Here, I'm able to fetch the top 10 keywords for each topic. Instead of getting only top 10 keywords, I'm trying to fetch all the keywords from each topic. Can anyone please suggest me regarding the same... My Code: from gensim.models import ldamodel import gensim.corpora; from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer; from sklearn.decomposition import LatentDirichletAllocation import warnings

spark sql create table will produce exception “$anonfun$createTransformFunc$2: (string) => array)” when this a array in the tempview

泪湿孤枕 提交于 2019-12-25 01:27:18
问题 the code is as follows: val tokenizer = new RegexTokenizer().setPattern("[\\W_]+").setMinTokenLength(4).setInputCol("sendcontent").setOutputCol("tokens") var tokenized_df = tokenizer.transform(sourDF) import org.apache.spark.sql.functions.{concat_ws} val mkString = udf((arrayCol: Seq[String]) => arrayCol.mkString(",")) tokenized_df=tokenized_df.withColumn("words",mkString($"tokens")).drop("tokens") tokenized_df.createOrReplaceTempView("tempview") sql(s"drop table if exists $result_table") sql

Gensim LDA Multicore Python script runs much too slow

南楼画角 提交于 2019-12-24 20:59:57
问题 I'm running the following python script on a large dataset (around 100 000 items). Currently the execution is unacceptably slow, it would probably take a month to finish at least (no exaggeration). Obviously I would like it to run faster. I've added a comment belong to highlight where I think the bottleneck is. I have written my own database functions which are imported. Any help is appreciated! # -*- coding: utf-8 -*- import database from gensim import corpora, models, similarities, matutils

How to use dlib's LDA

拟墨画扇 提交于 2019-12-24 19:41:46
问题 I want to fit dlib's LDA on my training set and apply the transformation to both the training and testing set. I wrote following minimal example to reproduce the problem. If you delete the sections that uses LDA, it should output a meaningful prediction. #include <iostream> #include <vector> #include <dlib/svm.h> int main() { typedef dlib::matrix<float, 2, 1> sample_type; typedef dlib::radial_basis_kernel<sample_type> kernel_type; dlib::svm_c_trainer<kernel_type> trainer; trainer.set_kernel

特征工程

百般思念 提交于 2019-12-24 17:51:42
转至博文:http://www.cnblogs.com/jasonfreak/p/5448385.html 知乎问答:https://www.zhihu.com/question/29316149 归一化,正则化:http://blog.csdn.net/u012102306/article/details/51940147 卡方检验:http://blog.csdn.net/sunshine_in_moon/article/details/45155803 目录 1 特征工程是什么? 2 数据预处理   2.1 无量纲化     2.1.1 标准化     2.1.2 区间缩放法     2.1.3 标准化与归一化的区别   2.2 对定量特征二值化   2.3 对定性特征哑编码   2.4 缺失值计算   2.5 数据变换 3 特征选择   3.1 Filter     3.1.1 方差选择法     3.1.2 相关系数法     3.1.3 卡方检验     3.1.4 互信息法   3.2 Wrapper     3.2.1 递归特征消除法   3.3 Embedded     3.3.1 基于惩罚项的特征选择法     3.3.2 基于树模型的特征选择法 4 降维   4.1 主成分分析法(PCA)   4.2 线性判别分析法(LDA) 5 总结 6 参考资料 1

LDA model prediction nonconsistance

冷暖自知 提交于 2019-12-24 11:37:12
问题 I trained a LDA model and load it into the environment to transform the new data: from pyspark.ml.clustering import LocalLDAModel lda = LocalLDAModel.load(path) df = lda.transform(text) The model will add a new column called topicDistribution . In my opinion, this distribution should be same for the same input, otherwise this model is not consistent. However, it is not in practice. May I ask the reason why and how to fix it? 回答1: LDA uses randomness when training and, depending on the

【文智背后的奥秘】系列篇——文本聚类系统

感情迁移 提交于 2019-12-22 19:56:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 版权声明:本文由文智原创文章,转载请注明出处: 文章原文链接: https://www.qcloud.com/community/article/131 来源:腾云阁 https://www.qcloud.com/community 一.文本聚类概述 文本聚类是文本处理领域的一个重要应用,其主要目标是将给定的数据按照一定的相似性原则划分为不同的类别,其中同一类别内的数据相似度较大,而不同类别的数据相似度较小。聚类与分类的区别在于分类是预先知道每个类别的主题,再将数据进行划分;而聚类则并不知道聚出来的每个类别的主题具体是什么,只知道每个类别下的数据相似度较大,描述的是同一个主题。因此,文本聚类比较适合用于大数据中热点话题或事件的发现。 文智平台提供了一套文本聚类的自动化流程,它以话题或事件作为聚类的基本单位,将描述同一话题或事件的文档聚到同一类别中。用户只需要按照规定的格式上传要聚类的数据,等待一段时间后就可以获得聚类的结果。通过文本聚类用户可以挖掘出数据中的热门话题或热门事件,从而为用户对数据的分析提供重要的基础。本文下面先对文本聚类的主要算法作介绍,然后再具体介绍文智平台文本聚类系统的原理与实现。 二.文本聚类主要算法 文本聚类需要将每个文档表示成向量的形式,以方便进行相似度的计算。词袋模型(bag of