Skip to Content
数据科学中的实用统计学(第2版)
book

数据科学中的实用统计学(第2版)

by Peter Bruce, Andrew Bruce, Peter Gedeck
October 2021
Intermediate to advanced
289 pages
8h 31m
Chinese
Posts & Telecom Press
Content preview from 数据科学中的实用统计学(第2版)
244
7
7-5:在 XOM CVX 的股票每日收益数据上使用 K-均值方法得到的簇(簇中心点使用粗黑符号
进行了突出显示)
7.2.2
 
K-
均值算法
通常,
K-
均值可以应用于有
p
个变量
X
1
,
,
X
p
的数据集。要得到
K-
均值的精确解,在计
算上非常困难,但可以使用启发式算法高效地算出一个局部最优解。
在这个算法中,首先需要用户确定
K
的值以及簇均值的一个初始集合,然后按以下步骤进
行迭代。
1.
将每条记录分配给按照距离的平方来测量的最近的簇均值。
2.
基于上面的记录分配,计算出新簇的均值。
当记录与簇的分配关系不再发生变化时,算法收敛。
对于第一次迭代,需要确定一个簇均值的初始集合。一般来说,可以随机地将每条记录分
配给
K
个簇中的一个,然后再算出这些簇的均值。
因为这种算法不能保证找到最优的解决方案,所以建议多次运行该算法,每次使用不同的
随机抽样来对算法进行初始化。进行了多次迭代之后,
K-
均值的结果就可以由具有最小的
簇内平方和的那次迭代给出。
R
函数
kmeans
nstart
参数可以指定算法随机启动的次数。例如,以下
R
代码使用
10
不同的簇均值启动算法,最后得到
5
个簇:
syms <- c( 'AAPL', 'MSFT', 'CSCO', 'INTC', 'CVX', 'XOM', 'SLB', 'COP',
'JPM', 'WFC', 'USB', 'AXP', 'WMT', 'TGT', 'HD', 'COST')
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

Python机器学习案例精解

Python机器学习案例精解

Posts & Telecom Press, Yuxi (Hayden) Liu

Publisher Resources

ISBN: 9787115569028