首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文本处理

文本处理
EN

Data Science用户
提问于 2017-02-03 07:58:43
回答 1查看 797关注 0票数 1

我对集群文本的分析是全新的,我正在使用Goodreads来获取图书概要。我的目标是对类似的书籍进行分组,例如:

  • 政治
  • 音乐
  • 传记等..。

虽然Goodread提供了体裁,但我想使用概要并使用文本。让我说,我将得到N本书的概要如下:

代码语言:javascript
复制
<description>
<![CDATA[
<b>Alternate cover edition can be found <a href="https://www.goodreads.com/book/show/10249685-dune" rel="nofollow">here</a>. </b> and <a href="https://www.goodreads.com/book/show/11273438-dune" rel="nofollow">here</a><br /><br />Here is the novel that will be forever considered a triumph of the imagination. Set on the desert planet Arrakis, <b>Dune</b> is the story of the boy Paul Atreides, who would become the mysterious man known as Muad'Dib. He would avenge the traitorous plot against his noble family--and would bring to fruition humankind's most ancient and unattainable dream.<br />A stunning blend of adventure and mysticism, environmentalism and politics, Dune won the first Nebula Award, shared the Hugo Award, and formed the basis of what it undoubtedly the grandest epic in science fiction.
]]>
</description>

我读过关于余弦相似性和新谷歌NLP的文章。但我想从以下几点开始:

  • 代表书的描述(特征,通常是一袋与TF-以色列国防军)。
  • 计算两本书的相似度(余弦相似度)

问题:

  • 创建所有书籍之间的余弦相似度矩阵的最有效算法是什么(N)
  • 如何在以上的基础上把集群图书放在一起?

任何其他的想法都会很棒。

EN

回答 1

Data Science用户

回答已采纳

发布于 2017-02-03 09:26:50

由于您要使用TF-国防军表示,您已经有了一个功能矩阵。要计算所有向量之间的余弦相似性,可以使用:

代码语言:javascript
复制
from sklearn.metrics.pairwise import cosine_similarity
similarity = cosine_similarity(tfidfmat)
#tfidfmat is your TF-IDF matrix

#使用numpy数组

要开始聚类,可以首先使用K-均值算法,然后使用余弦相似性作为距离度量。下面是是一个来自scikit的例子--学习集群文档。

进一步的尝试:如果您发现上面的方法不符合您的期望,请查看word2vec和doc2vec,而不是使用tfidf,它是一包单词方法,使用单词向量表示。这里是一个很好的博客,解释了这个概念。

票数 2
EN
页面原文内容由Data Science提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://datascience.stackexchange.com/questions/16713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档