资源简介
【模式识别小作业】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实现
相关资源
- 维纳滤波的matlab实现
- MATLAB 目标追踪单目标、多目标 可以运
- 数字图像处理图像的骨架生成和提取
- 数字基带/带通仿真 含BPSK、QPSK、16Q
- 双馈风力发电机MATLAB实现.zip
- 滤波器设计及Matlab代码
- matlab下多种方法进行心电信号去噪
- 电力电子技术学习指导习题集及仿真
- saber&MATLAB;联合仿真设置
- 基于MATLAB 的脉搏信号处理软件系统
- matlab最全的图像处理方面的工具箱
- matlab的gui的slider滑动条和可编辑文本
- matlab串口通信官方教程
- 多普勒效应的matlab仿真程序
- 加速度计原始数据进行matlab的fft分析
- 神经网络遥感图像分类matlab
- MATLAB教室人数统计源码,GUI,论文.
- MATLAB揭秘.pdf
- 用卷积神经网络实现彩色图像的超分
- matlab src1_9 压缩包
- Matlab揭秘
-
基于Matlab_Simuli
nk的聚光太阳能电池 - 基于MATLAB的光流估计法
- matlab 2016a 完全自学一本通附件pdf
- 程序及课件-Matlab仿真及其在光学课程
- 病虫害识别系统
- 人脸超分辨率识别matlab GUI图像处理毕
- Matlab70个绘图例程
- matlab串口数据实时图形显示
- 电力系统的matlab
评论
共有 条评论