资源简介
kmeans 算法,利用鸢尾花数据进行K均值分类,采用matlab编程
代码片段和文件信息
clear all;
close all;
clc;
[a1a2a3a4class] = textread(‘data1.txt‘ ‘%f%f%f%f%s‘‘delimiter‘ ‘‘);
a=[a1a2a3a4];
[b1b2b3b4class]=textread(‘data2.txt‘ ‘%f%f%f%f%s‘‘delimiter‘ ‘‘);
b=[b1b2b3b4];
[c1c2c3c4class]=textread(‘data3.txt‘ ‘%f%f%f%f%s‘‘delimiter‘ ‘‘);
c=[c1c2c3c4];
dat = [a;c;b];
hold on;
[m n]=size(dat);
for i=1:50
plot3(dat(i1)dat(i3)dat(i4)‘ro‘);
hold on
end
for i=51:100
plot3(dat(i1)dat(i3)dat(i4)‘g*‘);
hold on
end
for i=101:150
plot3(dat(i1)dat(i3)dat(i4)‘b.‘);
hold on
end
[cluster] = minmaxprobe(dat);
figure;
hold on;
for i=1:size(cluster1)
if cluster(i1) == 1
plot3(dat(i1)dat(i3)dat(i4)‘ro‘);
hold on
elseif cluster(i1) == 2
plot3(dat(i1)dat(i3)dat(i4)‘g*‘);
hold on
else
plot3(dat(i1)dat(i3)dat(i4)‘b.‘);
hold on
end
end
function [cluster] = minmaxprobe(x)
num = size(x1);
max_dis = 0;
mean_lable1 = 0;
mean_lable2 = 0;
initial = 51;
for i=1:num
dis1 = sqrt((x(i1)-x(initial1))^2+(x(initial2)-x(12))^2+(x(i3)-x(initial3))^2+(x(i4)-x(initial4))^2);
if (dis1>max_dis)
mean_lable1 = i;
max_dis = dis1;
end
end
for i=1:num
if(i~=mean_lable1)
dis1 = sqrt((x(i1)-x(initial1))^2+(x(initial2)-x(12))^2+(x(i3)-x(initial3))^2+(x(i4)-x(initial4))^2);
dis2 = sqrt((x(i1)-x(mean_lable11))^2+(x(i2)-x(mean_lable12))^2+(x(i3)-x(mean_lable13))^2+(x(i4)-x(mean_lable14))^2);
if(dis1>=dis2)
dis(i1) = dis2;
dis(i2) = i;
else
dis(i1) = dis1;
dis(i2) = i;
end
end
end
[ab] = find(dis==max(max(dis(:1))));
mean_lable2 = dis(a2);
mean_lable(11) = initial;
mean_lable(21) = mean_lable1;
mean_lable(31) = mean_lable2;
mean_lable
cluster(mean_lable(11)1) = 1;
cluster(mean_lable(21)1) = 2;
cluster(mean_lable(31)1) = 3;
for i = 1:num
if((i~=mean_lable(21))&&(i~=mean_lable(31)))
dis1 = sqrt((x(i1)-x(mean_lable(11)1))^2+(x(i2)-x(mean_lable(11)2))^2+(x(i3)-x(mean_lable(11)3))^2+(x(i4)-x(mean_lable(11)4))^2);
dis2 = sqrt((x(i1)-x(mean_lable(21)1))^2+(x(i2)-x(mean_lable(21)2))^2+(x(i3)-x(mean_lable(21)3))^2+(x(i4)-x(mean_lable(11)4))^2);
dis3 = sqrt((x(i1)-x(mean_lable(31)1))^2+(x(i2)-x(mean_lable(31)2))^2+(x(i3)-x(mean_lable(31)3))^2+(x(i4)-x(mean_lable(11)4))^2);
[ab] = find([dis1;dis2;dis3]==min(min([dis1;dis2;dis3])));
cluster(i1) = a;
end
end
% cluster
end
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2878 2018-05-07 17:50 K均值聚类\test1.m
目录 0 2018-09-11 18:55 K均值聚类
文件 1450 2018-05-07 17:45 K均值聚类\data1.txt
文件 1650 2018-05-07 17:46 K均值聚类\data2.txt
文件 1600 2018-05-07 17:47 K均值聚类\data3.txt
文件 2538 2018-05-07 18:15 K均值聚类\iris_dataset.txt
----------- --------- ---------- ----- ----
10116 6
- 上一篇:基于matlab的傅里叶频域滤波
- 下一篇:WVD时频代码matlab
相关资源
- Pattern Recognition and Machine Learning(高清
- MATLAB 编程 第二版 Stephen J. Chapman 著
- 均值滤波和FFT频谱分析Matlab代码
- 《MATLAB扩展编程》代码
- HDB3码、AMI码的MATLAB实现
- 3点GPS定位MATLAB仿真
- MATLAB数字信号处理85个实用案例精讲入
- matlab从入门到精通pdf94795
- 欧拉放大论文及matlab代码
- 跳一跳辅助_matlab版本
- 全面详解LTE MATLAB建模、仿真与实现
- MIMO-OFDM无线通信技术及MATLAB实现_孙锴
- MATLAB Programming for Engineers 4th - Chapman
- matlab 各种谱分析对比
- 分数阶chen混沌matlab程序
- 基于粒子群算法的非合作博弈的matl
- MATLAB车流仿真 包括跟驰、延误
- matlab空间桁架计算程序
- 基于MATLAB的图像特征点匹配和筛选
- DMA-TVP-FAVAR
- GPS信号的码捕获matlab代码.7z
- 一维光子晶体MATLAB仿真代码吸收率折
- newmark法源程序
- 传统关联成像、计算鬼成像matlab
- pri传统分选算法
- 摆动滚子推杆盘形凸轮设计
- 医学图像重建作业matlab源码
- Matlab实现混沌系统的控制
- 检测疲劳驾驶
- Matlab锁相环仿真-Phase Locked Loop.rar
评论
共有 条评论