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文本分析
特征工程与句法相似性
151
输出结果:
<6x20 sparse matrix of type '<class 'numpy.int64'>'
with 38 stored elements in Compressed Sparse Row format>
稀疏矩阵的效率非常高。它没有保存
6
×
20 = 120
个元素,而是只保存了
38
个!这
是因为稀疏矩阵忽略了所有零元素。
我们来试试看还原前面的文档词条矩阵。为此,我们必须将稀疏矩阵转换成一个(密
集的)数组。为了方便阅读,我们将其转换成
Pandas
的数据框:
pd.DataFrame(dt.toarray(), columns=cv.get_feature_names())
输出结果:
这个文档词条矩阵看上去与
one-hot
向量化器给出的非常相似。然而请注意,这
些列是按照字母顺序排列的,而且第
5
行出现了几个
2
。这个结果来自文档
"John
likes to watch movies. Mary likes movies too."
,其中有许多重复的单词。
5.4.2
案例:计算相似性
现在,找出文档之间的相似性很困难,因为统计文档中同一位置上均为
1
的元素个数还不够。在一般情况下,每个单词出现的次数可能会非常多,
我们必须考虑到这一点。在这种情况下,我们不能使用点积,因为点积对向量的长
度(文档中的单词数量)也很敏感。另外,在高纬度的向量空间中,欧几里德距离
Euclidean distance
)也发挥不了太大作用。这就是为什么在绝大多数情况下,我 ...
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