dbscan函数傻瓜式操作.docx
《dbscan函数傻瓜式操作.docx》由会员分享,可在线阅读,更多相关《dbscan函数傻瓜式操作.docx(8页珍藏版)》请在冰豆网上搜索。
![dbscan函数傻瓜式操作.docx](https://file1.bdocx.com/fileroot1/2023-6/23/4b1f2a40-23ec-407b-bdd9-e4d8660f19ce/4b1f2a40-23ec-407b-bdd9-e4d8660f19ce1.gif)
dbscan函数傻瓜式操作
1直接复制在MATLAB中运行
%clusterdata函数
clc,
clearall
closeall
yangben=load('ca.txt');%提取样本
t=size(yangben);%求矩阵行,列数
t1=t
(1);
t2=t
(2);
ca=yangben(:
2:
t2-1);%这里是调用100*9的实验数据(即去除第一列和最后一列)E=yangben(:
t2);
E(find(E==2))=1;
E(find(E==4))=2;
yangbenjieguo=E(:
:
);%为了进行正确率的计算,必须一致。
这里是替换并提取原始结果矩阵a
X=ca;
[class,type]=dbscan(X,2,[])
2.数据,请复制保存为ca.txt.第一列是编号,最后一列是结果。
聚类结束后,请注意转换结果
10025,5,1,1,1,2,1,3,1,1,2
5,4,4,5,7,10,3,2,1,2
3,1,1,1,2,2,3,1,1,2
6,8,8,1,3,4,3,7,1,2
4,1,1,3,2,1,3,1,1,2
8,10,10,8,7,10,9,7,1,4
1,1,1,1,2,10,3,1,1,2
2,1,2,1,2,1,3,1,1,2
2,1,1,1,2,1,1,1,5,2
4,2,1,1,2,1,2,1,1,2
1,1,1,1,1,1,3,1,1,2
2,1,1,1,2,1,2,1,1,2
5,3,3,3,2,3,4,4,1,4
1,1,1,1,2,3,3,1,1,2
8,7,5,10,7,9,5,5,4,4
7,4,6,4,6,1,4,3,1,4
4,1,1,1,2,1,2,1,1,2
4,1,1,1,2,1,3,1,1,2
10,7,7,6,4,10,4,1,2,4
6,1,1,1,2,1,3,1,1,2
7,3,2,10,5,10,5,4,4,4
10,5,5,3,6,7,7,10,1,4
3,1,1,1,2,1,2,1,1,2
1,1,1,1,2,1,3,1,1,2
5,2,3,4,2,7,3,6,1,4
3,2,1,1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
3,1,1,1,2,3,3,1,1,2
2,1,1,1,3,1,2,1,1,2
2,2,2,1,1,1,7,1,1,2
4,1,1,2,2,1,2,1,1,2
5,2,1,1,2,1,3,1,1,2
3,1,1,1,2,2,7,1,1,2
3,5,7,8,8,9,7,10,7,4
5,10,6,1,10,4,4,10,10,4
3,3,6,4,5,8,4,4,1,4
3,6,6,6,5,10,6,8,3,4
4,1,1,1,2,1,3,1,1,2
2,1,1,2,3,1,2,1,1,2
2,1,1,1,2,1,3,1,1,2
1,1,1,1,2,1,3,1,1,2
2,1,1,2,2,1,1,1,1,2
5,1,1,1,2,1,3,1,1,2
9,6,9,2,10,6,2,9,10,4
7,5,6,10,5,10,7,9,4,4
10,3,5,1,10,5,3,10,2,4
2,3,4,4,2,5,2,5,1,4
4,1,2,1,2,1,3,1,1,2
8,2,3,1,6,3,7,1,1,4
10,10,10,10,10,1,8,8,8,4
7,3,4,4,3,3,3,2,7,4
3clusterdata函数,MATLAB中输入typeclusterdata可以查看
functionT=clusterdata(X,vargin)
%CLUSTERDATAConstructclustersfromdata.
%T=CLUSTERDATA(X,CUTOFF)constructsclustersfromdataX.
%XisamatrixofsizeMbyN,treatedasMobservationsofN
%variables.CUTOFFisathresholdforcuttingthehierarchical
%treegeneratedbyLINKAGEintoclusters.When0%clustersareformedwheninconsistentvaluesaregreaterthan
%CUTOFF(seeINCONSISTENT).WhenCUTOFFisanintegerandCUTOFF>=2,%thenCUTOFFisconsideredasthemaximumnumberofclustersto
%keepinthehierarchicaltreegeneratedbyLINKAG
E.TheoutputTis
%avectorofsizeMcontaingaclusternumberforeachobservation.%%T=CLUSTERDATA(X,CUTOFF)isthesameas
%Y=pdist(X,'euclid');
%Z=linkage(Y,'single');
%T=cluster(Z,'cutoff',CUTOFF);%%T=CLUSTERDATA(X,'PARAM1',VAL1,'PARAM2',VAL2,...)providesmore
%controlovertheclusteringthroughasetofparameter/valuepairs.
%Validparametersarethefollowing:
%%ParameterValue
%'distance'AnyofthedistancemetricnamesallowedbyPDIST
%(the'minkowski'optioncanbefollowedbythe
%valueoftheexponentP).
%'linkage'AnyofthelinkagemethodsallowedbyLINKAG
E.
%'cutoff'Cutoffforinconsistentordistancemeasure.
%'maxclust'Maximumnumberofclusterstoform.
%'criterion'Either'inconsistent'or'distance'.
%$Revision:
1."1
3."
4.3$
ifnargin<2
error('stats:
clusterdata:
TooFewInputs','Notenoughinputarguments.');
end
%Determinewhichargsgowhere
pdistargs={};
linkageargs={};
donelist=[];
ifischar(vargin{1})
j=1;
while(jpname=vargin{j};
ifisequal(pname,'distance')
pdistargs(end+1)=vargin(j+1);
donelist(end+1:
end+2)=j:
j+1;
ifisequal(vargin{j+1},'minkowski')
if(length(vargin)>=j+2)&isnumeric(vargin{j+2})
pdistargs(end+1)=vargin(j+2);
donelist(end+1)=j+2;
j=j+1;
end
end
elseifisequal(pname,'linkage')
linkageargs(end+1)=vargin(j+1);
donelist(end+1:
end+2)=j:
j+1;
end
j=j+2;
end
vargin(donelist)=[];
end
iflength(vargin)==0
error('stats:
clusterdata:
MissingParameter',...
'MustspecifyaCUTOFForMAXCLUSTvalue.')
end
ifisempty(pdistargs)
pdistargs={'euclid'};
end
ifisempty(linkageargs)
linkageargs={'single'};
end
%Callcalculationroutineswiththeirownargs.Notethatthe
%pdistcalculationisdonewithinthelinkagefunction.
Z=linkage(X,linkageargs{1},pdistargs);
T=cluster(Z,vargin{:
});