Skip to Content
Python文本分析
book

Python文本分析

by Jens Albrecht, Sidharth Ramachandran, Christian Winkler
August 2022
Intermediate to advanced
441 pages
11h 26m
Chinese
China Electric Power Press Ltd.
Content preview from Python文本分析
238
|
第
8
章
或者,我们也可以用图形表示(将矩阵乘法所需的维度表示成图形),如图
8-1
所示。
在低维度下,分解计算可以得到精确的结果。但是高维度下所需的计算量太大,因
此近似分解就足够了。
文档
文档
单词
单词
主题
主题
图 8-1:非负矩阵分解原理图。矩阵 V 被分解成了 W 和 H
在文本分析的语境中,
W
和
H
都有自己的释义。矩阵
W
的行数与文档词条矩阵相
同,因此
W
的行映射成了主题(因此
W
是文档主题矩阵)。
H
的列数与特征数相同,
因此它展示了构成主题的特征(因此
H
是主题特征矩阵)。主题的数量(
W
的列数
与
H
的行数)可以任意选择。这个数量越小,分解的精度就越低。
8.3.1
案例:使用
NMF
创建文档的主题模型
通过
scikit-learn
,针对发言执行上述分解会非常简单。(几乎)所有的
主题模型都需要主题数量作为参数,我们随便选择
10
个主题(后面我们
就会发现这个选择很不错):
from sklearn.decomposition import NMF
nmf_text_model = NMF(n_components=10, random_state=42)
W_text_matrix = nmf_text_model.fit_transform(tfidf_text_vectors)
H_text_matrix = nmf_text_model.components_
与
TfidfVectorizer
类似,
NMF
也有一个
fit_transform
方法,可以返回其中一个
正因子矩阵。而其他因子则可以通过
NMF
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

工程战略的制定

工程战略的制定

Will Larson
Python实用技能学习指南

Python实用技能学习指南

Posts & Telecom Press, Robert Smallshire, Austin Bingham
精益AI

精益AI

Lomit Patel
Excel金融建模

Excel金融建模

Posts & Telecom Press, Shmuel Oluwa

Publisher Resources

ISBN: 9787519864446