Matlab实现k-means聚类算法

本文介绍了如何在Matlab中应用k-means聚类算法,详细解析了kmeans函数的用法,包括参数设置、距离度量选项以及迭代结果的显示。通过一个具体的例子,展示了如何将数据分为两类并进行可视化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

k-means是聚类中的一个十分经典的算法,具体的思想可以参考Andrew Ng的讲义《The k-means clustering algorithm》,这里不再赘述。

 

需要用到Matlab中的核心函数kmeans,具体用法可以参考Matlab命令: doc kmeans

IDX = kmeans(X,k)

[IDX,C] = kmeans(X,k)

[IDX,C,sumd] = kmeans(X,k)

[IDX,C,sumd,D] = kmeans(X,k)

partitions the points in the n-by-p data matrix X into k clusters.  Rows of X correspond to points, columns correspond to variables. 

n-by-1 vector IDX containing the cluster indices of each point. 

k cluster centroid locations in the k-by-p matrix C.

within-cluster sums of point-to-centroid distances in the 1-by-k vector sumd.

distances from each point to every centroid in the n-by-k matrix D.

还有一些可选的参数,包括:'distance', 'options', 'replicates'等。

'distance'表示距离,缺省为欧几里得距离,还包括绝对距离,cos距离,海明距离等。

'options'可以通过sta

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值