小编J. *_*amp的帖子

返回linq和的输入序列的元素

假设我有一个简单的列表,结构如下2列表:


letter|number

     a|1

     a|7

     b|2

     b|5
Run Code Online (Sandbox Code Playgroud)

我希望有一个Linq查询在"letter"列上分组,对"number"列的分组元素求和,另外还返回数组中的求和元素.这将导致下表:


a | 8 | {1,7}

b | 7 | {2,5}
Run Code Online (Sandbox Code Playgroud)

是)我有的:

public class GroupedRow {
    public int number { get; set; }
    public string letter { get; set; }
    public int[] elements { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

并在该计划中:

List<GroupedRow> listfromquery = numberletterlist.GroupBy(x => x.letter)
    .Select(grp => new GroupedRow() {
        number = grp.Sum(x => x.number)
        letter = grp.key.letter
        // elements=
    };
Run Code Online (Sandbox Code Playgroud)

即使我看到其他方法,我想在1 linq查询(如果可能),或另一种简单的快速方式.

c# linq

4
推荐指数
1
解决办法
99
查看次数

sklearn LatentDirichletAllocation 对新语料库的主题推断

我一直在使用 sklearn.decomposition.LatentDirichletAllocation 模块来探索文档语料库。经过多次迭代训练和调整模型(即添加停用词和同义词,改变主题数量),我对提炼出的主题相当满意和熟悉。作为下一步,我想将经过训练的模型应用于新的语料库。

是否可以将拟合模型应用于一组新文档以确定主题分布。

我知道这在 gensim 库中是可能的,您可以在其中训练模型:

from gensim.test.utils import common_texts
from gensim.corpora.dictionary import Dictionary

# Create a corpus from a list of texts
common_dictionary = Dictionary(common_texts)
common_corpus = [common_dictionary.doc2bow(text) for text in common_texts]

lda = LdaModel(common_corpus, num_topics=10)
Run Code Online (Sandbox Code Playgroud)

然后将训练好的模型应用于新的语料库:

Topic_distribtutions = lda[unseen_doc]
Run Code Online (Sandbox Code Playgroud)

来自:https : //radimrehurek.com/gensim/models/ldamodel.html

如何使用 LDA 的 scikit-learn 应用程序来做到这一点?

python lda topic-modeling scikit-learn

3
推荐指数
1
解决办法
1267
查看次数

标签 统计

c# ×1

lda ×1

linq ×1

python ×1

scikit-learn ×1

topic-modeling ×1