fcm函数傻瓜式操作doc.docx
- 文档编号:28276832
- 上传时间:2023-07-10
- 格式:DOCX
- 页数:33
- 大小:47.65KB
fcm函数傻瓜式操作doc.docx
《fcm函数傻瓜式操作doc.docx》由会员分享,可在线阅读,更多相关《fcm函数傻瓜式操作doc.docx(33页珍藏版)》请在冰豆网上搜索。
fcm函数傻瓜式操作doc
1直接复制在MATLAB中运行
%这是一个FCM函数处理的程序
clc,
clearall
closeal1
loadca.txt
yangben=load(,ca.txt');
t=si20(yangben);
tl=t(l):
t2=t
(2);
J=yangben(:
2:
t2-l);
data二J(:
:
);
N_CLUSTER=2;%该值需要根据要求更改,即分类数
[center,U,objfen]=fcm(data,NCLUSTER):
%FCM调用
N.CLUSTER
U二U'
2.数据,请复制保存为ca.txt.第一列是编号,最后一列是结果。
聚类结束后,请注意转换
结果
1000025.5.1.1.1.2.1.3.1.1.2
1002945.5.4.4.5.7.10.3.2.1.2
1015425.3.1.1.1.2.2.3.1.1.2
1016277.6.8.8.1.3.4.3.7.1.2
1017023.4.1.1.3.2.1.3.1.1.2
1017122.610.10.8.7.10.9.7.1.4
1018099.1.1.1.1.2.10.3.1.1.2
1018561.2.1.2.1.2.1.3.1.1.2
10330762.1丄1,2,1,1,1,5,2
1033078.4.2.1.1.2.1.2.1丄2
1035283.1丄1,1丄1,3,1,1,2
1036172.2.1丄1,2丄2,1,1,2
1041801.5.3.3.3.2.3.4.4.1.4
1043999.1.1.1.1.2.3.3.1.1.2
1044572.8.7.5.10.7.9.5.5.4.4
1047630.7.4.6.4.6.1.4.3.1.4
1048672.4.1.1.1.2.1.2.1.1.2
1049815.4.1丄1,2,1,3,1丄2
1050670.10.7.7.6.4.10.4.1.2.4
1050718.6.1.1.1.2.1.3.1.1.2
1054590.7.3.2.10.5.10.5.4.4.4
1054593.10.5.5.3.6.7.7.10.1.4
1056784,3丄1丄2,1,2丄1,2
1059552,1,1,1,1,2,1,3丄1,2
1065726.5.2.3.4.2.7.3.6.1.4
1066373.3.2.1.1.1.1.2.1.1.2
1066979.5.1.1.1.2.1.2.1.1.2106744421丄1,2,1,2,1,1,2
1070935.1.1.3.1.2.1.1.1.1.2
1070935.3.1.1.1.1.1.2.1.1.2
1071760.2.1.1.1.2.1.3.1.1.2
1072179.10.7.7.3.8.5.7.4.3.4
1074610.2.1.1.2.2.1.3.1丄2
1075123.3.1.2.1.2.1.2.1.1.2
1079304.2.1.1.1.2.1.2.1.1.2
1080185.10.10.10.66.1.8.9.1.4
1081791.6.2.1.1.1.1.7.1.1.2
1084584.5.4.4.9.2.10.5.6.1.4
1091262.2.5.3.3.6.7.7.5.1.4
1099510.10.4.3.1.3.3.6.5.2.4
1100524.6.10.10.2.8.10.7.3.3.4
1102573.5.6.5.6.10.1.3.1.1.4
1103608.10.10.10.4.8.1.8.10.1.4
1103722.1.1.1.1.2.1.2.1.2.2
1105257.3.7.7.4.4.9.4.8.1.4
1105524.1丄1,1,2,1,2,1,1,2
1106095.4.1.1.3.2.1.3.1.1.2
1106829.7.8.7.2.4.63.62.41108370,9,5,&1,2,3,2,1,5,4
1108449.5.3.3.4.2.4.3.4.1.4
1110102.10.3.6.2.3.5.4.10.2.4
1110503.5.5.5.8.10.8.7.3.7.4
1110524.10.5.5.6.8.8.7.1.1.4
1111249.10.6.6.3.4.5.3.6.1.4
1112209.8.10.10.1.3.6.3.9.1.4
1113038.8.2.4.1.5.1.5.4.4.41113483,5,2,3丄6,10,5,1,1,4
1113906.9.5.5.2.2.2.5.1.1.4
1115282.5.3.5.5.3.3.4.10.1.4
1115293.1.1.1.1.2.2.2.1.1.2
1116116.9.10.10.1.10.63.3.1.4
1116132.6.3.4.1.5.2.3.9.1.4
1116192.1.1.1.1.2.1.2.1.1.2111699&10,4,2丄3,2,4,3,10,4
1117152.4.1.1.1.2.1.3.1.1.21118039,5,3,4丄&10,4,9,1,41120559,8,3,&3,4,9,&9,&4
1121732.1.1.1.1.2.1.3.2.1.2
1121919.5.1.3.1.2.1.2.1.1.21123061,6,10,2,&10,2,7,8,10,41124651丄3,3,2,2,1,7,2,1,2
1125035.9.4.5.10.6.10.4.61.4
1126417.10.6.4.1.3.4.3.2.3.4
1131294.1.1.2.1.2.2.4.2.1.2
1132347.1.1.4.1.2.1.2.1.1.2
1133041.5.3.1.2.2.1.2.1.1.2
1133136.3.1.1.1.2.3.3.1.1.2
1136142.2.1.1.1.3.1.2.1.1.2
1137156.2.2.2.1.1.1.7.1.1.2
114397&4丄1,2,2,1,2,1,1,2114397&5,2,1,1,2,1,3,1,1,21147044,3丄1,1,2,2,7丄1,2
1147699.3.5.7.8.8.9.7.10.7.4
1147748.5.10.6.1.10.4.4.10.10.4
11482763.3.6.4.5.64.4.1.4
1148873.3.6.6.6.5.10.6.63.41152331,4丄1,1,2,1,3丄1,2115554621,1,2,3,1,2丄1,21160476,2丄1,1,2,1,3,1,1,2
1164066.1.1.1.1.2.1.3.1.1.2
1165297.2.1.1.2.2.1.1.1.1.2
1165790.5.1.1.1.2.1.3.1.1.2
1165926.9.6.9.2.10.6.2.9.10.4
1166630.7.5.6.10.5.10.7.9.4.4
1166654,10,3,5丄10,5,3,10,2,4
1167439.2.3.4.4.2.5.2.5.1.41167471,4丄2丄2,1,3丄1,2
1168359.62.3.1.6.3.7.1.1.4
1168736.10.10.10.10.10.1.8.8.8.4
1169049.7.3.4.4.3.3.3.2.7.43fem函数源代码(在MATLAB中输入typefem可以查看)functionfidx,C,sumD,D]=kmeans(X,k,varargin)%KMEANSK-meansclustering.
%IDX=KMEANS(X,K)partitionsthepointsintheN-by-Pdatamatrix
%XintoKclusters.Thispartitionminimizesthesum,overall
%clusters,ofthewithin-clustersumsofpoint-to-cluster-centroid
%distances.RowsofXcorrespondtopoints,columnscorrespondto
%variables.KMEANSreturnsanN-by-1vectorIDXcontainingthe
%clusterindicesofeachpoint.Bydefault,KMEANSusessquared
%Euclideandistances.
%
%KMEANStreatsNaNsasmissingdata,andremovesanyrowsofXthat%containNaNs.
%
%[IDX,CJ=KMEANS(X,K)returnstheKclustercentroidlocationsin%theK-by-PmatrixC.
%
%[IDX,C,SUMD]=KMEANS(X,K)returnsthewithin-clustersumsof%point-to-centroiddistancesinthe1-by-KvectorsumD.
%
%
%
%
%
%
%
%
%
%
%
%
[IDX,C,SUMD,D]=KMEANS(X,K)returnsdistancesfromeachpointtoeverycentroidintheN-by-KmatrixD.
[...]=KMEANS(...,'PARAM1',vail,'PARAM2',val2,...)allowsyoutospecifyoptionalparametername/valuepairstocontroltheiterativealgorithmusedbyKMEANS.Parametersare:
'Distance*-Distancemeasure,inP-dimensionalspace,thatKMEANSshouldminimizewithrespectto.Choicesare:
{'sqEuclidean'}-SquaredEuclideandistance
'cityblock'-Sumofabsolutedifferences,a.k.a.LI
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
'cosine'-Oneminusthecosineoftheincludedangle
betweenpoints(treatedasvectors)
Correlation1・Oneminusthesamplecorrelationbetweenpoints(treatedassequencesofvalues)
'Hamming'-Percentageofbitsthatdiffer(only
suitableforbinarydata)
'Starf-Methodusedtochooseinitialclustercentroidpositions,
sometimesknownas"seeds”.Choicesare:
「sample'}・SelectKobservationsfromXatrandom
uniforni,-SelectKpointsuniformlyatrandomfromtherangeofX.NotvalidforHammingdistance.
Cluster1-Performpreliminaryclusteringphaseon
random10%subsampleofX.ThispreliminaryphaseisitselfinitializedusingSample1.
matrix-AK-by-Pmatrixofstartinglocations.Inthiscase,youcanpassin[]forK,andKMEANSinfersKfromthefirstdimensionofthematrix.Youcanalsosupplya3Darray,implyingavaluefor'Replicates'fromthearrayfsthirddimension.
Replicates1-Numberoftimestorepeattheclustering,eachwithanewsetofinitialcentroids[positiveintegerI{1)J
'MaxiteF-Themaximumnumberofiterations[positiveinteger|{100}J
*EmptyAction*-Actiontotakeifaclusterlosesallofitsmemberobservations・Choicesare:
{^rror1}・Treatanemptyclusterasanerror
'drop1-Removeanyclustersthatbecomeempty,andsetcorrespondingvaluesinCandDtoNaN・
Singleton1・Createanewclusterconsistingoftheoneobservationfurthestfromitscentroid・
'Display'-Displaylevelf'off|('notify')|'final'|'iter'1
Example:
X=[randn(20,2)+ones(20,2);randn(20,2)-ones(20,2)];[cidx,ctrs]=kmeans(X,2,'dist'/city','rep',5,'disp','final');
plot(X(cidx==1,l),X(cidx==1,2),T.‘,...
X(cidx==2,1),X(cidx==2,2);b.\ctrs(:
1),ctrs(:
2),'kx‘);
SeealsoLINKAGE,CLUSTERDATA,SILHOUETTE・
%KMEANSusesatwo-phaseiterativealgorithmtominimizethesumof%point-to-ccntroiddistances,summedoverallKclusters・Thefirst%phaseuseswhattheliteratureoftendescribesas"batch"updates,%whereeachiterationconsistsofreassigningpointstotheirnearest%clustercentroid,allatonce,followedbyrecalculationofcluster%centroids・Thisphasemaybethoughtofasprovidingafastbut
%potentiallyonlyapproximatesolutionasastartingpointforthe
%secondphase・Thesecondphaseuseswhattheliteratureoften
%describesas"on-line11updates,wherepointsareindividually
%reassignedifdoingsowillreducethesumofdistances,andcluster
%centroidsarerecomputedaftereachreassignment.Eachiteration
%duringthissecondphaseconsistsofonepassthoughallthepoints.
%KMEANScanconvergetoalocaloptimum,whichinthiscaseisa
%partitionofpointsinwhichmovinganysinglepointtoadifferent
%clusterincreasesthetotalsumofdistances・Thisproblemcanonlybe
%solvedbyaclever(orlucky,orexhaustive)choiceofstartingpoints.
%J
%References:
%
%[1JSeber,G.A.F.,MultivariateObservations,Wiley,NewYork,1984.
%[2]Spath,H.(1985)ClusterDissectionandAnalysis:
Theory,FORTRAN
%Programs,Examples,translatedbyJ.Goldschmidt,HalstedPress,
%NewYork,226pp.
%Copyright1993-2004TheMathWorks,Inc.
%$Revision:
1.4.4.5$$Date:
2004/03/0221:
49:
12$
ifnargin<2
errorCstats:
kmeans:
TooFewInpulsTAtleasttwoinputargumentsrequired.1);
end
ifany(isnan(X(:
)))
warning('stats:
kmeans:
MissingDataRemovedTRemovingrowsofXwithmissingdata.1);X=X(~any(isnan(X),2),:
);
end
%npointsinpdimensionalspace
[n,p]=size(X);
Xsort=[J;Xord=IJ;
pnames={distance*^tart*Replicates11maxiter*'emptyactiorf'display'};
dflts={'sqeuclidean'Sample'[]100'error1'notify'};
[eid^errmsg,distance,start,reps,maxit,emptyact,display!
...
=statgetargs(pnames,dflts,varargin{:
});
if〜isempty(eid)error(sprirHfCstats:
kmeans:
%s;eid),errmsg);
end
讦ischar(distance)
distNames={,sqeuclidean\'cityblock\lcosine\,correlation\'hamming,};
i=strmatch(lowcr(distancc),distNames);
iflength(i)>1error(lstats:
kmeans:
AmbiguousDistance\...
'Ambiguous"distance”parametervalue:
%s.\distance);
clscifiscmpty(i)error(stats:
kmeans:
UnknownDistance\…
'Unknownndistanceuparametervalue:
%s.\distance);
end
distance=distNames{i};
switchdistance
case'cityblock'
[Xsort,Xord]=sort(X,l);
case'cosine'
Xnorm=sqrt(sum(X.A2,2));
ifany(min(Xnoirn)<=eps(max(Xnorm)))errorC^tatsrkmeansrZeroDataForCos1,…
『Somepointshavesmallrelativemagnitudes,makingthem\…EffectivelyzeroAnEitherremovethosepoints,orchoosea;…'distanceotherthanncosinen.fJ);
end
X=X./Xnorm(:
ones(1,p));
caseCorrelation1
X=X-repmat(mean(X,2),1,p);
Xnorm=sqrt(sum(X.A2,2));
ifany(min(Xnorm)<=eps(max(Xnorm)))error(lstats:
kmeans:
ConstantDataForCorr\...
「Somepointshavesmallrelativestandarddeviations,makingthem;...Effectivelyconstant.\nEitherremovethosepoints,orchoosea;…'distanceotherthanHcorrelationH.r]);
end
X=X./Xnorm(:
ones(1,p));
case'hamming
if~alI(ismcmbcr(X(:
),[O1]))error(lstats:
kmeans:
NonbinaryDataForHamm\...
^on-binarydatacannotbeclusteredusingHammingdislance/);end
end
els
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- fcm 函数 傻瓜 操作 doc
![提示](https://static.bdocx.com/images/bang_tan.gif)