资源简介
【模式识别小作业】K均值聚类K-means clustering+Matlab实现+UCI的Iris和Seeds数据集+分类问题 包含:完整全套代码+readme+报告

代码片段和文件信息
%This program is based on the data set Iris
%The original data set contains three kinds of flowers
%Here the Kmeans method is processed to do the three-category problem
%The flower name in the data set is changed to a numeric symbol of 1 2 3
clear;
clc;
%%%%%%%%%%%%%%Data preprocessing section%%%%%%%%%%%%%%%%
% Read data
f=fopen(‘iris.data‘);%Open dataset file
data=textscan(f‘%f%f%f%f%s‘); %Read file content
D=[];% Used to store attribute values
for i=1:length(data)-1
D=[D data{1i}];
end
fclose(f);
lable=data{1length(data)};
n1=0;n2=0;n3=0;
% Find the index of each type of data
for j=1:length(lable)
if strcmp(lable{j1}‘Iris-setosa‘)
n1=n1+1;
index_1(n1)=j;% Record the index belonging to the “Iris-setosa“ class
elseif strcmp(lable{j1}‘Iris-versicolor‘)
n2=n2+1;
index_2(n2)=j;% Record the index belonging to the “Iris-versicolor“ class
elseif strcmp(lable{j1}‘Iris-virginica‘)
n3=n3+1;
index_3(n3)=j;% Record the index belonging to the “Iris-virginica“ class
end
end
% Retrieve each type of data according to the index
class_1=D(index_1:);
class_2=D(index_2:);
class_3=D(index_3:);
Attributes=[class_1;class_2;class_3];
%Iris-setosa is marked as 1;Iris-versicolor is marked as 2
%Iris-virginica is marked as 3
I=[1*ones(n11);2*ones(n21);3*ones(n31)];
Iris=[Attributes I];% Change the name of the flower to a number tag
save Iris.mat Iris % Save all data as a mat file
%Save all data as a txt file
f=fopen(‘iris1.txt‘‘w‘);
[mn]=size(Iris);
for i=1:m
for j=1:n
if j==n
fprintf(f‘%g \n‘Iris(ij));
else
fprintf(f‘%g‘Iris(ij));
end
end
end
fclose(f);
%Directly take the number of categories k = 3
Iris_test=Iris;
[mn]=size(Iris_test);
acc_rateqian=0;
%traverse all samples every 5 samples to calculate the optimal 3 sample
%points that can be used as the initial sample center
for bianli1=1:5:50
for bianli2=51:5:100
for bianli3=101:5:150
u1=Iris(bianli1:);
u2=Iris(bianli2:);
u3=Iris(bianli3:);
u1_qian=u1(1:4);
u2_qian=u2(1:4);
u3_qian=u3(1:4);
diedai=0;
while 1
%Divide each sample into different classes
for i=1:m
d1=0;
d2=0;
d3=0;
for j=1:n-1
d1=d1+(Iris_test(ij)-u1(1j))^2;
d2=d2+(Iris_test(ij)-u2(1j))^2;
d3=d3+(Iris_test(ij)-u3(1j))^2;
end
%Determine which sample center is closest to each point
if (d1<=d2)&&(d1<=d3)
Ir
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 174202 2019-12-01 20:37 1932938_JiahaoLu_assignment3\irisdata\gongzuoqu.pdf
文件 4551 2019-11-05 08:31 1932938_JiahaoLu_assignment3\irisdata\iris.data
文件 1059 2019-12-01 20:34 1932938_JiahaoLu_assignment3\irisdata\Iris.mat
文件 2708 2019-12-01 20:34 1932938_JiahaoLu_assignment3\irisdata\iris1.txt
文件 2708 2019-12-01 20:35 1932938_JiahaoLu_assignment3\irisdata\iris_first.txt
文件 2708 2019-12-01 20:35 1932938_JiahaoLu_assignment3\irisdata\iris_result.txt
文件 7242 2019-12-09 09:54 1932938_JiahaoLu_assignment3\irisdata\kmeans.m
文件 99791 2019-12-01 20:37 1932938_JiahaoLu_assignment3\irisdata\result.PNG
文件 853 2019-12-09 09:56 1932938_JiahaoLu_assignment3\README.txt
文件 278283 2019-12-09 12:18 1932938_JiahaoLu_assignment3\Report.docx
文件 352743 2019-12-09 12:18 1932938_JiahaoLu_assignment3\Report.pdf
文件 167151 2019-12-01 20:25 1932938_JiahaoLu_assignment3\seeddata\gongzuoqu.pdf
文件 5832 2019-12-09 09:45 1932938_JiahaoLu_assignment3\seeddata\kmeans.m
文件 91198 2019-12-01 20:26 1932938_JiahaoLu_assignment3\seeddata\result.PNG
文件 9300 2019-11-05 21:30 1932938_JiahaoLu_assignment3\seeddata\seeds_dataset.txt
文件 9498 2019-12-01 20:18 1932938_JiahaoLu_assignment3\seeddata\seed_first.txt
文件 9498 2019-12-01 20:18 1932938_JiahaoLu_assignment3\seeddata\seed_result.txt
目录 0 2019-12-09 09:51 1932938_JiahaoLu_assignment3\irisdata
目录 0 2019-12-09 12:19 1932938_JiahaoLu_assignment3\seeddata
目录 0 2019-12-09 12:18 1932938_JiahaoLu_assignment3
----------- --------- ---------- ----- ----
1219325 20
- 上一篇:MATLAB 目标追踪单目标、多目标 可以运行
- 下一篇:维纳滤波的matlab实现
相关资源
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
- k近邻算法matlab实现
- matlab识别系统
评论
共有 条评论