如何用matlab通过聚类分析的方法实现把一个14*14实数矩阵里的数据分成五类并能知道每个数据所属于的类别

如何用matlab通过聚类分析的方法实现把一个14*14实数矩阵里的数据分成五类并能知道每个数据所属于的类别,第1张

已经知道类别数的话一般用k-均值就可以了,14维的矩阵是一行表示一个sample吗?一般是一个数据由一行表示,这样话你总共有14个数据了,matlab里自带的有k均值聚类的,关键看你聚类的依据是什么?一般就是高斯距离了。

MATLAB是以矩阵为基本的数据运算单位,它能够很好的与C语言进行混合编程,对于符号运算,其可以直接调用maple的命令,增加了它的适用范围。下面就为大家介绍MATLAB如何读写Excel数据文件的步骤

材料/工具

电脑,MATLAB软件

读取excel文件

1

双击打开excel数据文件夹

2

使用MATLAB中提供的系统函数xlsread函数,其主要的调用形式为:a=xlsread('filenamexls'),其中a表示读入文件所保存的变量名称,filenamexls(或者filenamexlsx)表示excel数据文件

3

对于上图所示的数据文件,只需要使用下面的命令进行读取即可:A = xlsread('dataxlsx')

如果数据文件保存在excel的某个sheet中,使用方式为: A = xlsread('dataxlsx','Sheet1')

写入excel文件

1

需要使用MATLAB中提供的系统函数xlswrite()函数,其主要的调用形式为:

xlswrite('filenamexls',variable);

其中variable表示需要写入Excel文件的变量名称,filenamexls(或者filenamexlsx)表示excel数据文件,help帮助文档中对xlswrite()函数的介绍如下图所示:

2

对于上图所示的数据文件,只需要使用下面的命令进行读取即可:xlswrite('outputxlsx',A)

%%自己写的

%%给你个直接聚类的实例,x中有m行n列,即m个信号,每个信号有n个参数

clc

clear

x=[752 014 186 091 521;

7515 016 211 074 493;

7219 013 152 069 465;

7235 013 137 083 487;

7274 010 141 072 499;

7329 0033 107 017 315;

7372 0033 077 028 278;];

%%系统距离法共包含四种具体聚类方法,此处给你最大和最小距离法

Y = pdist(x,'cityblock');

%%最短距离法

Z1 = linkage(Y,'single');

subplot(1,2,1);

[H,T] = dendrogram(Z1,'colorthreshold','default')

set(H,'LineWidth',2)

grid on;title('最短距离法聚类图')

%%最长距离法

Z2 = linkage(Y,'complete');

subplot(1,2,2);

[H,T] = dendrogram(Z2,'colorthreshold','default')

set(H,'LineWidth',2)

grid on;title('最长距离法聚类图')

直接用kmeans函数。。。

idx = kmeans(X,k)

idx = kmeans(X,k,Name,Value)

[idx,C] = kmeans(___)

[idx,C,sumd] = kmeans(___)

[idx,C,sumd,D] = kmeans(___)

idx = kmeans(X,k) performs k-means clustering to partition the observations of the n-by-p data matrix X into k clusters, and returns an n-by-1 vector (idx) containing cluster indices of each observation Rows of X correspond to points and columns correspond to variables

By default, kmeans uses the squared Euclidean distance measure and the k-means++ algorithm for cluster center initialization

example

idx = kmeans(X,k,Name,Value) returns the cluster indices with additional options specified by one or more Name,Value pair arguments

For example, specify the cosine distance, the number of times to repeat the clustering using new initial values, or to use parallel computing

example

[idx,C] = kmeans(___) returns the k cluster centroid locations in the k-by-p matrix C

example

[idx,C,sumd] = kmeans(___) returns the within-cluster sums of point-to-centroid distances in the k-by-1 vector sumd

example

[idx,C,sumd,D] = kmeans(___) returns distances from each point to every centroid in the n-by-k matrix D

推荐去看一下K-mean聚类算法。原理相当于一个传教士的故事,有一批传教士n个,分散到一个城市各个区域传教,城市里的每个人到离他最近的一个传教士所在位置去听教。下一次,传教士为了照顾更多的人,会根据上一次到他那里所有人的平均位置,去传教(相当于当前人位置的重心),人们再根据自己的远近,考虑去哪个传教士那。最后稳定下来(收敛到你想要的条件或者次数),各个区域就分好了。

result = resultreplaceAll(">\\s<", "><")replaceAll("<\\([^>|^\\])\\>", "");

String json = result;

Matcher matcher = Patterncompile("<([^>|^/])>")matcher(result);

while(matcherfind()){

for (int i = 0; i < matchergroupCount(); i++) {

String s = matchergroup(i+1);

json = jsonreplaceAll("<"+s+">([^<|^\"])</"+s+">", "\""+s+"\":\"$1\",");

}

}

以上就是关于如何用matlab通过聚类分析的方法实现把一个14*14实数矩阵里的数据分成五类并能知道每个数据所属于的类别全部的内容,包括:如何用matlab通过聚类分析的方法实现把一个14*14实数矩阵里的数据分成五类并能知道每个数据所属于的类别、MATLAB 代码,用高斯混合模型聚类分析处理xlsx文件,只需要三行代码、用matlab实现最大最小距离法聚类分析等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/10057517.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-04
下一篇2023-05-04

发表评论

登录后才能评论

评论列表(0条)

    保存