kmeans 初步学习小结

接触kmeans 算法比较长时间了,但是一直没好好明白怎么回事。推荐几个好点的链接。

http://coolshell.cn/articles/7779.html

http://blog.csdn.net/zouxy09/article/details/9982495

http://www.360doc.com/content/13/1122/14/10724725_331295214.shtml

运用matlab函数的一个最基本程序

yangben= load(‘F:\iris.txt‘);
s=size(yangben);
hang=s(1);
lie=s(2);
x=yangben(:,1:4);
opts=statset(‘Display‘,‘final‘);
k=3;
[idx,ctrs]=kmeans(x,k,‘Distance‘,‘city‘,‘Replicates‘,5,‘options‘,opts);
     plot(x(idx==1,1),x(idx==1,2),‘r.‘,...
     x(idx==2,1),x(idx==2,2),‘b.‘,...
     x(idx==3,1),x(idx==3,2),‘g.‘);
 ctrs(:,1),ctrs(:,2),ctrs(:,3),‘kx‘;

总的来说,还可以,是因为数据集比较权威。

贴上help里kmeans 的帮助文档,以后再研究。暂且就会用这个函数就行了。看完这个,终于可以好好看看稀疏编码进行特征提取的问题了。

help kmeans
kmeans K-means clustering.
IDX = kmeans(X, K) partitions the points in the N-by-P data matrix X
into K clusters. This partition minimizes the sum, over all clusters, of
the within-cluster sums of point-to-cluster-centroid distances. Rows of X
correspond to points, columns correspond to variables. Note: when X is a
vector, kmeans treats it as an N-by-1 data matrix, regardless of its
orientation. kmeans returns an N-by-1 vector IDX containing the cluster
indices of each point. By default, kmeans uses squared Euclidean
distances.

kmeans treats NaNs as missing data, and ignores any rows of X that
contain NaNs.

[IDX, C] = kmeans(X, K) returns the K cluster centroid locations in
the K-by-P matrix C.

[IDX, C, SUMD] = kmeans(X, K) returns the within-cluster sums of
point-to-centroid distances in the 1-by-K vector sumD.

[IDX, C, SUMD, D] = kmeans(X, K) returns distances from each point
to every centroid in the N-by-K matrix D.

[ ... ] = kmeans(..., ‘PARAM1‘,val1, ‘PARAM2‘,val2, ...) specifies
optional parameter name/value pairs to control the iterative algorithm
used by kmeans. Parameters are:

‘Distance‘ - Distance measure, in P-dimensional space, that kmeans
should minimize with respect to. Choices are:
‘sqEuclidean‘ - Squared Euclidean distance (the default)
‘cityblock‘ - Sum of absolute differences, a.k.a. L1 distance
‘cosine‘ - One minus the cosine of the included angle
between points (treated as vectors)
‘correlation‘ - One minus the sample correlation between points
(treated as sequences of values)
‘Hamming‘ - Percentage of bits that differ (only suitable
for binary data)

‘Start‘ - Method used to choose initial cluster centroid positions,
sometimes known as "seeds". Choices are:
‘sample‘ - Select K observations from X at random (the default)
‘uniform‘ - Select K points uniformly at random from the range
of X. Not valid for Hamming distance.
‘cluster‘ - Perform preliminary clustering phase on random 10%
subsample of X. This preliminary phase is itself
initialized using ‘sample‘.
matrix - A K-by-P matrix of starting locations. In this case,
you can pass in [] for K, and kmeans infers K from
the first dimension of the matrix. You can also
supply a 3D array, implying a value for ‘Replicates‘
from the array‘s third dimension.

‘Replicates‘ - Number of times to repeat the clustering, each with a
new set of initial centroids. A positive integer, default is 1.

‘EmptyAction‘ - Action to take if a cluster loses all of its member
observations. Choices are:
‘error‘ - Treat an empty cluster as an error (the default)
‘drop‘ - Remove any clusters that become empty, and set
the corresponding values in C and D to NaN.
‘singleton‘ - Create a new cluster consisting of the one
observation furthest from its centroid.

‘Options‘ - Options for the iterative algorithm used to minimize the
fitting criterion, as created by STATSET. Choices of STATSET
parameters are:

‘Display‘ - Level of display output. Choices are ‘off‘, (the
default), ‘iter‘, and ‘final‘.
‘MaxIter‘ - Maximum number of iterations allowed. Default is 100.

‘OnlinePhase‘ - Flag indicating whether kmeans should perform an "on-line
update" phase in addition to a "batch update" phase. The on-line phase
can be time consuming for large data sets, but guarantees a solution
that is a local minimum of the distance criterion, i.e., a partition of
the data where moving any single point to a different cluster increases
the total sum of distances. ‘on‘ (the default) or ‘off‘.

Example:

X = [randn(20,2)+ones(20,2); randn(20,2)-ones(20,2)];
opts = statset(‘Display‘,‘final‘);
[cidx, ctrs] = kmeans(X, 2, ‘Distance‘,‘city‘, ...
‘Replicates‘,5, ‘Options‘,opts);
plot(X(cidx==1,1),X(cidx==1,2),‘r.‘, ...
X(cidx==2,1),X(cidx==2,2),‘b.‘, ctrs(:,1),ctrs(:,2),‘kx‘);

时间: 2024-08-29 04:07:36

kmeans 初步学习小结的相关文章

数据结构 第一章学习小结

数据结构   第一章学习小结 1.数据结构第1章的心得体会: 这周学习了数据结构的绪论及第一章.初步了解了数据结构与算法的相关概念,一开始看书看视频时觉得还挺抽象的,不能够完全理解.但是反复多看了几遍之后,结合例题,自己去操作去跑代码,慢慢觉得容易理解接受起来了.由于现在以网课形式进行教学,老师上课的同时基本还是靠自己去理解学习.当然老师也发挥很大的作用,比如让我们更深入的了解递归的空间复杂度为什么与问题规模有关,又怎样去找到该函数的临界值等等.既锻炼了我们深入思考的能力,也让我们更加清楚了解不

git学习小结

背景:最近因为工作原因,需要将以前的代码库由bitbucket重新布置在一台服务器上,所以就学习了下git,特此记录下 在167这台机器上搭建apache,用做git server,由于以前apache都已经搭好了,所以这里只配置git server 就可以了,此处贴出配置: 服务器搭好了,来到配置中的root目录,git clone https://[email protected]/XXXX 此时,库和服务器都搭好了,用于新库测试的机器也可以从git server上克隆库了,来,我们来试试从

网络编程学习小结

几种网络编程方式: ISAPI.CGI.WinInet.Winsock 它们之间的差别: 1)  ISAPI主要是开发基于浏览器client与server端程序.效率比CGI方式高,并且也扩展了CGI没有的一些功能.(基于TCP/IP模型中的应用层) 2)  CGI主要是开发基于浏览器client与server端程序.(基于TCP/IP模型中的应用层) 3)  WinInet主要是开发client程序.(基于TCP/IP模型中的应用层) 4)  Winsock主要是基于socket来开发clie

MogileFS学习小结

大纲: 一.关于MogileFS 二.常见分布式文件系统 三.MogileFS基本原理 四.MogileFS的实现 一.关于MogileFS 当下我们处在一个互联网飞速发展的信息社会,在海量并发连接的驱动下每天所产生的数据量必然以几何方式增长,随着信息连接方式日益多样化,数据存储的结构也随着发生了变化.在这样的压力下使得人们不得不重新审视大量数据的存储所带来的挑战,例如:数据采集.数据存储.数据搜索.数据共享.数据传输.数据分析.数据可视化等一系列问题. 传统存储在面对海量数据存储表现出的力不从

201671010130 2016-2017-2 《Java程序设计》第四周学习小结

第四周学习小结 本次实验巩固了上次实验分隔数并求和的题,目前这个题有两种做法,一种是不断对数10求余,余数保存在sum中,然后左移一位,直到余数为零.另一种就是将数字强制转换成一个字符串数组String s=String.valueOf(num),根据方法s.toCharArray()将字符分离出来,据"x"-"0"=x,unicode码值相减即可得x的值. 父类和子类能够看两个交集,super关键字是否能够看做一个子类和超类的接口呢? 在子类中可以增加域.增加方法

LinQ的初步学习与总结

嘿嘿,说起来ORM和LinQ,就感觉离我好遥远的,在学校是没有学习的,所以总感觉学习了LinQ就是大神,现在嘛,终于也体会一点,感觉LinQ只是初步学习,没有太难,当然以后使用在项目中就没有这样的简单啦,下面就全面的总结一下LinQ的其中一部分,LinQ有三部分:LinQ TO Object:LinQ TO SQL ;LinQ TO XML.而在这里我先来总结一下LinQ TO Object的学习吧 一.初步认识LinQ to Object static void Main(string[] a

初识ASP.NET---点滴的积累---ASP.NET学习小结

差不多十多天前学习完了北大青鸟的学习视频,没想到没几天的时间就看完了XML视频和牛腩的Javascript视频.学习完了也该总结总结,理理自己的思路,消化一下自己学习到的东西. 视频中的理论知识并不是很多,以例子驱动学起来也不会他过于乏味.全部的学习内容大概的可以用下图表示. 个人感觉这套视频的体系感不是很强,每一集之间老师的串联并不是做得很好,向我等没有教材的有些小的知识无从知晓.但是不能不说这套视频确很适合初学者学习,老师讲解的也不错,从此我也算是入门. 当然要想进一步的了解ASP.NET并

Jquery Easy UI初步学习(二)datagrid的使用

第一篇学的是做一个管理的外框,接着就是数据datagrid绑定了,这里我用asp.net mvc3来做的,主要就是熟悉属性.方法. 打开easyui的demo 就可以看到如下一段代码: 和上篇一样class="easyui-datagrid", data-options="...",这是一样的,其他我在网上查了查,并做了整理 DataGrid 属性 参数名 类型 描述 默认值 title string Datagrid面板的标题 null iconCls strin

8086汇编学习小结———实时更新

初学IBM-PC 8086,对INT指令不是很理解.现从网上总计如下: 表:DOS系统功能调INT 21H AH 功能 调用参数 返回参数 00 程序终止(同INT 20H) CS=程序段前缀 01 键盘输入并回显 AL=输入字符 02 显示输出 DL=输出字符 03 异步通迅输入 AL=输入数据 04 异步通迅输出 DL=输出数据 05 打印机输出 DL=输出字符 06 直接控制台I/O DL=FF(输入)DL=字符(输出) AL=输入字符 07 键盘输入(无回显) AL=输入字符 08 键盘