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文本分析
非监督学习
主题建模与聚类
263
8.9
案例:使用聚集来挖掘文本数据的结构
除了主题建模之外,还有很多其他非监督方法。虽然不是所有方法都适
合文本数据,但许多聚类算法都可以使用。与主题建模相比,使用聚类时,
我们需要知道每个文档(或段落)只会分配到一个簇。
聚类非常适合单一主题的文本
我们的案例有一个合理的假设,即每个文档只属于一个簇,因为一个段
落之中不太可能包含太多不同的内容。对于大型文本片段,考虑到主题
混合的情况,我们还是应该使用主题建模。
大多数聚类方法都需要簇的数量作为参数,但也有一些(比如均值偏移)可以猜测
簇的正确数量。后者大多无法很好地处理稀疏数据,因此不适合文本分析。在这个
案例中,我们决定使用
K-
平均聚类(
k-means clustering
),但
birch
或谱聚类(
spectral
clustering
)应该也可以。关于
K-
平均聚类的文章有很多。
4
聚类的速度比主题建模慢很多
大多数聚类算法都需要花费大量时间,远超
LDA
。所以,在执行下面的
聚类代码片段时,请做好等待将近一个小时的思想准备。
scikit-learn
的聚类
API
与主题建模很相似:
from sklearn.cluster import KMeans
k_means_text = KMeans(n_clusters=10, random_state=42)
k_means_text.fit(tfidf_para_vectors)
KMeans(n_clusters=10, random_state=42)
但是,找出究竟有多少个段落属于哪个簇非常容易。一切必要的信息都 ...
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

精益AI

精益AI

Lomit Patel
构建知识图谱

构建知识图谱

Jesus Barrasa, Jim Webber
写给系统管理员的Python脚本编程指南

写给系统管理员的Python脚本编程指南

Posts & Telecom Press, Ganesh Sanjiv Naik

Publisher Resources

ISBN: 9787519864446