凯鲁嘎吉
用书写铭记日常,最迷人的不在远方

MATLAB高斯混合数据的生成

作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/

高斯混合模型的基本原理:聚类——GMM,MATLAB中GMM聚类算法:MATLAB中“fitgmdist”的用法及其GMM聚类算法。本文主要讨论如何用MATLAB人工生成符合高斯混合模型的数据,文中给出生成二维数据与三维数据的案例。

1. 二维数据生成

1.1. 程序

function data=generate_GMM()
%前两列是数据,最后一列是类标签
%数据规模
N=300;
%数据维度
dim=2;
%%
%混合比例
para_pi=[0.4 0.15 0.15 0.15 0.15];
%第一类数据
mul=[0 0]; % 均值
S1=[1 0;0 1]; % 协方差
data1=mvnrnd(mul, S1, para_pi(1)*N); % 产生高斯分布数据
%第二类数据
mu2=[4 4];
S2=[2 -1;-1 2];
data2=mvnrnd(mu2,S2,para_pi(2)*N);
%第三类数据
mu3=[-4 4];
S3=[2 1;1 2];
data3=mvnrnd(mu3,S3,para_pi(3)*N);
%第四类数据
mu4=[-4 -4];
S4=[2 -1;-1 2];
data4=mvnrnd(mu4,S4,para_pi(4)*N);
%第五类数据
mu5=[4 -4];
S5=[2 1;1 2];
data5=mvnrnd(mu5,S5,para_pi(5)*N);
%显示数据
plot(data1(:,1),data1(:, 2),'bo');
hold on;
plot(data2(:,1),data2(:,2),'ro');
plot(data3(:,1),data3(:,2),'go');
plot(data4(:,1),data4(:,2),'ko');
plot(data5(:,1),data5(:,2),'mo');
data = [data1, ones(para_pi(1)*N,1); data2, 2*ones(para_pi(2)*N,1); data3, 3*ones(para_pi(3)*N,1); data4, 4*ones(para_pi(4)*N,1); data5, 5*ones(para_pi(5)*N,1)];
%%
%将数据集存入文件
fid1=fopen('gauss_data.txt','w');
for i=1:N
    for d=1:dim+1
        fprintf(fid1, '%.4f ', data(i, d));
    end
    fprintf(fid1, '\n');
end
fclose(fid1);

1.2. 图像

1.3. 数据

-0.545510895080894	-0.376258667656416	1
0.374552558897674	0.507947640696775	1
-0.543488756435145	-1.37429164174078	1
1.81674776949293	0.137611179142222	1
-1.13998872085001	1.01039299620699	1
1.14786721735582	0.207004703224859	1
-1.70294252385711	-0.103099215770313	1
0.0412850370487988	-0.195177061697310	1
-0.0290779721068919	-0.135740617792583	1
1.20156687436050	0.785293100134734	1
-0.436725759877869	1.81621157992917	1
1.54564665100393	0.0521836769281596	1
-1.47074023395844	-1.03631822338874	1
-0.592323493112913	0.0368269076747419	1
-1.20464720277048	0.386236582716893	1
-0.0268027179877074	0.946328586724753	1
0.689163840469742	0.363460264428701	1
-1.22578553639022	1.45577857770520	1
1.98235629235162	1.23957524822078	1
0.722139387530663	0.135722562156936	1
0.426061788318672	-0.640173428232819	1
-1.06473611766422	-1.79093796498374	1
-0.0208890425378482	-1.78188146258966	1
-0.335868994910233	-1.22740346873807	1
-0.998438482903848	1.04283040882465	1
1.87048144588107	-0.00711709671883774	1
-1.09383228203225	-1.10301743848135	1
-1.20635174064544	1.04079783475122	1
-1.45468265207870	0.387024751709480	1
0.477438173899314	-1.56885894319954	1
0.395517166570296	1.63566457794523	1
0.0127565610991932	-1.31747151564540	1
0.588244305798010	-0.770606857586131	1
0.292251846731924	-1.56405947064427	1
0.728195887049746	0.637052412407101	1
0.916384718400930	-1.51351246140111	1
-1.29608649587100	0.169458582238240	1
2.20003870472710	0.0639531351969648	1
-0.601447112807249	0.640878604433810	1
0.961926051186633	1.52088956213435	1
0.730358994297656	1.98972700194211	1
-2.17215248555966	-1.09045030833633	1
-0.350959881900495	0.833789718172194	1
-0.349589841180652	-1.91963579276902	1
-1.06240791125327	1.43138152092021	1
0.304127023543034	1.17021454099990	1
-1.72933045779437	-1.54142367954478	1
-0.598896004160902	-0.105925554825273	1
-1.31011037743746	-1.58021974549522	1
2.36570028887232	-1.09880959658705	1
-1.26743690700607	0.0837653841878213	1
1.23414029010661	1.30262183813727	1
1.10550496182430	-1.15415172874195	1
1.67104117072622	0.135275892935019	1
1.70798624510336	0.882302210646749	1
0.563155580569765	1.81376295782830	1
-0.251182581897459	1.33566417915374	1
-1.88295982534046	0.575127428345159	1
0.169665209677480	0.874143372144739	1
1.66500477262456	-0.177812863248393	1
-1.52518812841798	-0.664826413112643	1
-0.310696321302611	-0.883332521493689	1
0.400332024230491	0.530777065822867	1
0.230678403945063	0.426444757506126	1
-1.49437426451061	-2.42389297892765	1
-0.359152477917947	0.151728546222352	1
-2.00864455513353	2.32358798338343	1
-0.979477048746326	1.38118885402575	1
1.54448192457976	0.151875567931926	1
-0.293612697408936	-0.436934755150954	1
1.35489766124073	2.34256831156063	1
0.597498265543298	0.121733895853054	1
0.581096571550465	1.17453838970134	1
-0.561552403053525	-0.771004698512474	1
0.917751266060919	-0.657506326182589	1
-0.641924288663851	-0.479375568051963	1
-0.363404932649308	0.676855927372856	1
-1.11415448619610	0.235979896507873	1
0.986335597529911	-0.655301174154837	1
-0.251493520240138	1.09713018877592	1
1.24781504258504	-1.42003482739768	1
-0.699650589017584	1.26589092346096	1
1.26999492311366	0.810680984781717	1
-0.429850276664512	-0.198687954797670	1
-1.52207229775273	0.749815780538519	1
0.0446125639186305	0.0299683762124543	1
0.987983190454411	-0.612913405189806	1
0.800503104827616	0.918230554969138	1
-1.08343410496977	-0.733932667894764	1
1.76914639732084	1.55116726073502	1
0.986959900933206	-0.663725674981786	1
-1.36104628754580	1.30619567448118	1
0.0550199981573708	0.331657475411092	1
0.338974101191037	-0.859239935132467	1
-1.14124191451059	0.0223083748809411	1
0.358376148834936	1.95334737608871	1
0.632621192872067	0.693497444406873	1
-0.330060047581271	0.347134256096482	1
0.0762545593670635	-1.26382021965231	1
0.432432069335672	0.780865579724367	1
-1.10984737506597	-0.226376879877599	1
0.973408237206523	-0.369816426260412	1
1.01178818947520	-0.185059622746829	1
0.450873476806951	-0.462633883999610	1
-0.868977983745262	1.33846758967167	1
0.857310060734281	-0.577977792199812	1
-2.06965874587350	0.110515274540505	1
-0.204421480496499	-0.769171619841190	1
0.624388816884225	2.03367134489104	1
-1.20705716828968	1.15343255555437	1
1.81335576028267	0.849682684264488	1
0.994905245705837	1.53886387077322	1
0.579005595985224	-1.58750073493957	1
1.20031539783778	0.479588829491639	1
2.15151625102986	1.11948856191139	1
1.38455526292789	-0.422564879467687	1
-0.965035030674835	0.213521202486582	1
1.72950610850028	-0.112681878056680	1
-0.0111424529195589	1.92758349368306	1
-0.608182225006691	-0.743062527373251	1
6.26191132851482	2.87420234778389	2
1.46708536828177	4.25933314661017	2
4.03512816519817	3.55838996904576	2
1.56291290267162	5.93213541837081	2
2.96236859827081	4.37151621826476	2
3.64143063677362	4.88689583161662	2
6.38266804240388	3.34558908666101	2
5.41309508707033	3.35837439232833	2
2.30763884124060	4.64357035916882	2
1.94146522926749	3.59676642990087	2
1.52805472175875	5.48742166863894	2
3.37947088416179	4.13546180253651	2
3.21758346388238	1.75465508363488	2
4.92098227770249	2.72247830961419	2
5.52880682285822	2.44875436837217	2
5.64261670568491	2.82376694427663	2
4.24043924394131	3.89438173035117	2
5.46466404478820	4.28382676990317	2
3.95567234720622	3.66422513585000	2
4.09085068078046	7.23388238849599	2
2.99902277594830	4.00041225146169	2
3.85403068887563	3.22625573591014	2
5.21472864087325	4.32253841766911	2
2.84692148498926	3.44846498856175	2
4.01186710155383	2.02718224126495	2
4.30344011638458	2.91792209130873	2
3.02572894146083	6.92568297671023	2
2.52390865374576	4.67273361504838	2
3.29669675181033	5.10650923628543	2
2.67404933672749	6.37163861175736	2
4.14608767191083	4.45153308892660	2
2.69680280080912	5.18811828663690	2
1.51437308217565	5.05846837008456	2
3.93462302848637	4.30358583470654	2
2.70493715992304	3.73426722910466	2
4.28769182326535	4.93248502602472	2
2.08595382511258	4.74263599702177	2
3.81219187638740	5.50053543094262	2
5.43715368098522	3.90844411861587	2
4.74483548517909	3.18409801820196	2
4.01495899961387	3.52442373699206	2
2.01031761274835	6.63092272795666	2
3.38200833205790	4.87869800104605	2
2.15486571629534	2.64912537458821	2
4.61913522058550	1.17807382732939	2
-2.41983520346350	6.85250494294405	3
-3.91895198693660	4.30466947036677	3
-2.13339943346212	6.46315559386203	3
-3.02101000134472	6.28320929687944	3
-5.25130856752767	5.12603408807742	3
-5.59803186523091	3.26150858527381	3
-5.69301728266434	2.11993425665485	3
-5.58200771470702	0.879147529661482	3
-5.75547440020193	2.38389935224039	3
-6.38355622563180	4.48307844365673	3
-4.71212878642699	3.75762092589917	3
-4.14495549006060	2.18789588281711	3
-2.53442114176800	3.12820506221048	3
-5.48593353106808	1.05573675748163	3
-4.69694792261799	4.32324665818441	3
-4.53287897254505	4.31558634252341	3
-3.40824627224202	2.82618015057078	3
-4.54362215345362	1.90971151401584	3
-2.58926813815895	5.80021670830004	3
-3.84341520256589	4.88917870913694	3
-3.42204804497922	4.23019459522267	3
-4.13229646764044	2.97591908765228	3
-3.96744300534690	5.19020008301123	3
-3.95410257082111	3.92228119811007	3
-2.38177252199409	6.82035106813690	3
-4.88273180490767	5.20027313219846	3
-2.90011672474735	6.81908441253178	3
-5.59693327231870	6.34390256873062	3
-3.65555788343370	2.41110355975260	3
-4.93485685527032	2.79678180870763	3
-3.48504201208711	6.26622339218588	3
-4.54778116908779	4.53678733910660	3
-4.16788088460357	1.98016388606870	3
-7.13141235432678	2.50098865284353	3
-3.82942576858549	3.60639122698253	3
-2.78090623000099	4.93165228176749	3
-3.75308089259298	3.06115467845300	3
-4.40204438880523	4.14589819485963	3
-1.84084098927512	3.48444117374196	3
-1.70189927604420	6.06507753034884	3
-5.96158916139604	4.49241737024208	3
-5.04990024101003	3.65858083982453	3
-5.44605518486153	2.31171509463054	3
-2.62360844695056	1.35243403718315	3
-5.71885561684177	3.22238799248740	3
-5.15558931162033	-1.93151831428770	4
-3.13819376759068	-4.26842286451585	4
-4.65128978496079	-4.66813132800655	4
-6.55160390643011	-1.63312515289099	4
-3.19554916278024	-4.59379356680950	4
-3.66227304508280	-4.12082943673340	4
-4.49289926473170	-3.14984190235144	4
-4.55548884160883	-4.95301034623535	4
-3.70812542145989	-6.51356102416401	4
-1.71989911425951	-6.01173781843615	4
-0.539004834471935	-7.14448691144402	4
-1.91587781399240	-6.80703912184080	4
-6.87395794730588	-3.56173142735883	4
-4.75364662811086	-1.77970472900929	4
-4.38871174218452	-5.70642976639587	4
-3.87755277810941	-5.78917234218382	4
-1.66410091182604	-6.54273715357697	4
-4.64450490872372	-4.03634872386426	4
-6.06611766638436	-3.75980150984485	4
-4.91302254323549	-3.37229009600523	4
-4.18487396930512	-4.03317654889994	4
-4.94396440446167	-3.99816469680926	4
-5.90500974456669	-0.658597778449720	4
-4.80674949908200	-2.12197424958233	4
-6.53625885527321	-4.96538843253712	4
-6.67118214488468	-3.85329368548873	4
-5.08548875004801	-3.02479056014923	4
-4.94199867939672	-5.97539351893420	4
-6.16431877278395	-2.08464799600191	4
-3.54905294343501	-4.64416276395015	4
-4.34651923612607	-4.60275778691262	4
-4.40655863311961	-3.89710437970330	4
-4.83813790882019	-3.50063589897614	4
-5.47137155975461	-0.633027093974476	4
-2.45351326558628	-6.64985635880677	4
-5.19013185289929	-2.14267250944901	4
-6.48490166569892	-3.23069729729028	4
-4.97850262601172	-3.56174043414819	4
-5.52493818792063	-3.11696548001527	4
-2.65756545002045	-3.77786643835108	4
-6.86367695213169	-2.14826102222898	4
-4.20123561303810	-2.65343044360313	4
-4.54764420476797	-3.07361975587910	4
-2.18647469486795	-3.74929421191038	4
-5.07228681009131	-3.89428860055849	4
3.17302980178845	-5.39031953879009	5
4.45960273242076	-2.36846155877649	5
5.24099720742394	-5.69962995830296	5
3.56899925360007	-6.28570690919855	5
4.20159066008819	-1.58986296682819	5
6.13798449363983	-2.02253957739510	5
5.06700175465161	-3.80479250240493	5
2.86247020041003	-6.02094889758587	5
3.77035825050206	-2.32677099886967	5
4.99518069973419	-5.16267665183900	5
2.10263236352861	-8.34806464740769	5
4.12985525865002	-5.77249471085627	5
5.22783306815519	-2.71136270887530	5
1.80804441328560	-4.95427032123393	5
1.81079007671092	-4.43865538009938	5
5.05426328485665	-3.21994804948600	5
4.39956086448591	-1.27681521098911	5
-0.0791554892517015	-8.31170377350323	5
2.82799553567766	-4.03949663519130	5
3.20361435469073	-4.89917919754429	5
2.97719190341939	-5.35014527781680	5
7.48957765290125	-1.70834454697736	5
3.94557969039702	-3.39325860845618	5
3.66144920989468	-4.21774086304387	5
5.12352713663710	-2.89875162602726	5
3.97463780486113	-2.55353097282383	5
1.95572161389881	-6.79713136111470	5
4.15455541179760	-3.08278711709991	5
3.89909907570780	-2.58134994204057	5
7.02778219584157	-3.39646965696710	5
3.47794604458990	-5.91509213081594	5
5.19288006346659	-4.67919733613364	5
4.89042010198797	-3.46282598001945	5
4.04483939390608	-3.58599481578122	5
5.03792687927419	-4.66925536085279	5
5.21171110193382	-4.86589708577224	5
4.06913858477176	-3.12572398674435	5
4.46932412600276	-5.19551962881950	5
3.52508022350430	-4.19734682862160	5
5.45374435410425	-3.54101673467541	5
3.53811357548697	-5.22688932165462	5
4.47819796042730	-4.44919901840050	5
2.75688743817806	-5.60458322936945	5
2.50534610439532	-5.35941563176474	5
2.08963538325247	-6.14523524386922	5

同时数据已存入当前目录的文件“gauss_data.txt”中。

2. 三维数据生成

2.1. 程序

function data=generate_GMM()
%前两列是数据,最后一列是类标签
%数据规模
N=300;
%数据维度
dim=3;
%%
%混合比例
para_pi=[0.1 0.2 0.3 0.4];
%第一类数据
mul=[0 0 0]; % 均值
S1=[1 0 0;0 1 0;0 0 1]; % 协方差
data1=mvnrnd(mul, S1, para_pi(1)*N); % 产生高斯分布数据
%第二类数据
mu2=[3 3 2];
S2=[2 -1 0;-1 1 0;0 0 1];
data2=mvnrnd(mu2,S2,para_pi(2)*N);
%第三类数据
mu3=[-3 3 1];
S3=[2 1 0;1 2 0;0 0 1];
data3=mvnrnd(mu3,S3,para_pi(3)*N);
%第四类数据
mu4=[0 -3 3];
S4=[2 1 0;1 1 0;0 0 2];
data4=mvnrnd(mu4,S4,para_pi(4)*N);
%显示数据
plot3(data1(:,1),data1(:, 2),data1(:,3),'bo');
hold on;
grid on
xlabel('x');
ylabel('y');
zlabel('z');
plot3(data2(:,1),data2(:,2),data2(:,3),'ro');
plot3(data3(:,1),data3(:,2),data3(:,3),'go');
plot3(data4(:,1),data4(:,2),data4(:,3),'ko');
data = [data1, ones(para_pi(1)*N,1); data2, 2*ones(para_pi(2)*N,1); data3, 3*ones(para_pi(3)*N,1); data4, 4*ones(para_pi(4)*N,1)];
%%
%将数据集存入文件
fid1=fopen('gauss_data.txt','w');
for i=1:N
    for d=1:dim+1
        fprintf(fid1, '%.4f ', data(i, d));
    end
    fprintf(fid1, '\n');
end
fclose(fid1);

2.2. 图像

2.3. 数据

2.49843747778172	-0.460263982717900	0.926213263510532	1
0.344363940565677	0.183803197329987	-0.592596618971808	1
1.51495409493848	-1.00077063634156	1.42720702412040	1
-2.22985506128415	0.443834535891559	2.27820838669181	1
-0.720939190484627	1.18580789933626	-1.62476852958396	1
-0.308579945523786	-1.35024988178629	-2.44577799952649	1
-0.321837686711218	-0.482587253319734	0.0125282318746073	1
-1.13246932505719	-0.0324602353944920	0.705875854273454	1
-1.17979116037789	0.0170636084606657	0.0121834842846798	1
-1.59495940633115	-0.0960891860381253	-1.23860565163178	1
-0.238072926666054	-0.293133285171206	3.13633987972424	1
-0.900087525142363	-1.03924742019756	1.38542294580792	1
-1.28191166393303	0.605731890499142	1.04241118916645	1
-1.82870431878706	1.50570356578587	-2.19237656562187	1
0.475589087694975	0.410717730270373	1.20028305951021	1
0.150260875174452	0.916252656197516	-0.747712381188694	1
-1.60246504874026	-0.405372454001307	1.26780393762904	1
1.99411324341624	-0.0965621653282794	-0.204162416163832	1
0.612290358680033	0.164542950693545	0.121884852921529	1
0.291149162823226	-0.955916506466084	-1.73459429211643	1
-0.647215619249269	-0.655955642766331	1.20508858042327	1
0.495121953506736	0.881847619515268	-0.279462203814666	1
1.36893754821876	0.0580880581352123	-0.998666427666221	1
-2.00542485916349	-1.25539294619184	0.0369730707026779	1
0.293348876186443	-0.589359819346870	-0.358772856873272	1
-0.818658558703714	2.06751728279068	1.09599054124806	1
-0.293309049600295	-0.0634639175716548	0.967794251039837	1
0.925030468575763	-0.910070871855287	-1.65902513235640	1
-1.50298384459762	1.03159565518800	1.31384919551221	1
-1.82830676992021	0.708726157033793	-1.23244228382176	1
4.05647056505806	3.15779278067951	1.33554596356026	2
2.80821058515555	3.81742131283227	2.15083179871381	2
0.689413026615452	4.74387814905321	1.24695271109973	2
4.54086597015512	2.55613015933163	1.39896264244928	2
1.69690723483602	4.46825622520101	1.47510918748751	2
5.55238975032377	-0.295635003555867	1.82089013916159	2
3.62626258261583	1.30566471288204	-0.133898012480930	2
3.73735026690620	3.26583235654822	3.70607753584556	2
2.16345737090853	2.76313852722265	3.70449327772986	2
3.66795486609899	2.75982149307769	0.953949844125312	2
3.34992926613246	2.80886852240528	2.94729101721180	2
2.80042557814606	3.39384245921333	4.12217252869437	2
3.10489926411870	3.95786809475060	1.29603218400640	2
0.0469984056864776	4.46843416465705	3.53712151726741	2
2.47585448507785	3.08706469590746	2.92082143150995	2
1.68083372956454	3.59697916051383	0.985854370865028	2
3.42914884555317	2.33181599368835	0.634141522744353	2
1.86386784349807	4.33465483002277	2.44553950185964	2
1.23584151178778	4.75064663837965	1.29295114341203	2
2.92206222231454	3.34382592996769	0.960717672132152	2
4.33424030463856	1.89265524114487	1.22129258331317	2
0.681039763013596	3.79968449293932	0.385670737536172	2
3.40749585853358	3.88607766490946	2.46385697332908	2
4.27014672014641	2.91273702579306	2.05521378456440	2
2.97723849649204	2.38340459726243	0.447356760347354	2
0.524044407934072	3.34771412925916	1.41646566990192	2
2.83733404725494	2.69651695523908	1.03406301520104	2
2.51175607927568	3.85640741108295	2.46578392847227	2
0.439496748973050	3.63796684378395	2.81960085715231	2
3.02916636555290	3.65846733347827	1.77894885249181	2
2.90058863403041	2.29274769872908	1.32609145625505	2
2.95807930336693	3.08693005408050	0.752822925845977	2
-0.745172214954278	5.21006999851789	3.11503281710424	2
2.40706405937875	1.51966708315590	1.16733326999331	2
5.27976775583405	2.86568767230792	1.51629429757050	2
0.819505859681578	3.67526851879069	1.67070013463305	2
0.248876280042175	5.00707421658782	4.18523616304716	2
1.41951079147412	3.84593900162790	2.38723714551302	2
4.65578462102459	3.12826856645431	0.708927545618616	2
3.14404118912926	2.37599094087654	2.70575137329287	2
1.60475249163368	4.40476024265404	2.07056306224623	2
4.77176905876137	2.58796643331653	3.23080180166649	2
1.66151854695769	3.36485569786061	3.07899064729435	2
4.39651517393641	2.60615043803276	1.04981713639719	2
1.91574150233070	2.82139467093036	2.79833162843550	2
2.78066598127283	4.27617377866690	1.23182673860975	2
2.79065044378098	2.42854864485248	0.994091739710354	2
2.25229309431098	4.47048252156054	2.52917803278316	2
2.42817876409434	3.89826379622712	1.89148821213051	2
4.35256215050249	4.68795729113736	1.83000399979505	2
3.86508035164427	3.10284399721756	2.91003235721308	2
1.33880835606307	4.46475122224117	1.71249996579546	2
2.62630515719235	3.52174113124233	2.60106484284540	2
2.41743571368160	3.54684195854090	1.08247360198120	2
5.17571247612839	2.28100186183683	2.11140418355563	2
5.04102282380700	3.37729812739364	0.961767638237232	2
2.54568168952880	3.98990734828420	0.603584159177279	2
4.77263468615723	2.55806365037606	2.58149505930596	2
3.45124079002683	2.76319090540820	2.48068801741237	2
3.55509753930443	2.72631775475948	2.43532671450374	2
-3.72575522934799	3.41374117906808	0.564089937319531	3
-1.49530724735220	2.74114360611538	1.76324108253431	3
-3.78255380026534	1.21636414523540	-0.966508204498694	3
-2.04201053378278	3.51211509303177	-0.862931203383614	3
-4.30204893367853	0.133241422396216	0.723629446599856	3
-2.76557404098756	4.39787848098502	2.06638524014308	3
-1.76424638369006	3.86397228189524	-1.29179866755891	3
-3.49739697039177	2.69755359368435	1.87054093470835	3
-4.28416197387197	2.94200093803046	2.15150305261657	3
-2.21362894897064	1.96510101051233	1.23119499645831	3
-4.00190293410484	-1.10006331982181	-1.46972018018716	3
-3.23960168174870	3.04204993335470	1.77154049980377	3
-3.20660315725286	2.89725222584771	0.634626240639286	3
-2.89098551292571	2.88123726415650	0.0185430078079879	3
-4.38219253242212	2.12386011761066	0.772251397088894	3
-3.06725936803190	3.28611459297746	0.944064155475691	3
-2.48126115051638	2.85085458228916	1.37451253073099	3
-3.98489605338984	3.41702506440920	-1.02933179345756	3
-4.30781941081652	2.57627209418364	2.05975983293786	3
-3.80987007984826	1.55101332137724	2.67934573292633	3
-2.52913461754473	4.52898121721011	2.63701996386624	3
-2.36116487252144	3.60232594721072	1.25310450987092	3
-2.38047624090841	4.85800969795735	1.18821490042032	3
-6.46178940302624	1.04786159458319	2.15040962051384	3
-3.17068691134666	4.48967856738831	1.66243076476216	3
-4.45634864375172	2.26636438842492	1.17466031112808	3
-3.00247874771026	3.22402779265543	1.91193009773979	3
-0.708001964766505	4.14400091662013	-1.19480361492525	3
-3.64656087747163	3.25215594580317	2.28591799005819	3
-1.80794858987325	1.57746109280536	1.12637280227824	3
-3.07840023627948	4.46343945153496	0.633732611546657	3
-2.60291186602479	2.94862528207529	0.538040772871204	3
-3.40194058295917	1.69927191858877	0.744931026546819	3
-2.07354389320229	3.81333077699234	2.59091490309264	3
-3.31121323903503	2.66240811462464	0.370684751651984	3
-1.98449190593178	4.38834725432366	2.94401985916100	3
-2.84920284621129	1.07124241655639	1.85022152021315	3
-5.84978836391596	1.70652732838089	0.815882887003180	3
-3.49408763743340	1.79441146769616	0.893863219723915	3
-4.36068048541878	2.78537602755144	-0.663259115013664	3
-6.35215626584504	1.58503944372197	1.62725980532343	3
-1.61477266272688	4.36060031012489	1.16570780904460	3
-4.13869603210270	1.90834167406601	1.48708077856366	3
-3.91441666181063	3.43186713789223	2.22959505403030	3
-3.58209976998703	1.79455049646167	1.40429052691219	3
-3.44306021044775	1.77393636549355	1.75756952899977	3
-1.34363386052024	5.20797383857814	0.434678482968388	3
-3.89977296599357	-0.892352518073186	1.67385500037343	3
-1.80073896681135	5.24954433361703	-0.432993588640519	3
-2.15218877962698	2.51901959950753	-0.772895201212734	3
-5.17001700397002	2.51618386714205	2.03466301566771	3
-2.08176489955814	2.67235157373199	2.00538129857907	3
-1.97962807809447	5.42545068197313	-1.25107236532691	3
-1.04400565765742	4.28190658790702	1.79442013471345	3
-2.57420250852749	2.39952370325060	-0.343453220682345	3
-3.88936720678901	1.77839041326796	1.69179824633125	3
-5.13999175739771	1.98605693321621	0.480346775160482	3
-4.44012463542111	1.69928161355648	2.37292087954860	3
-4.87084165022710	3.89384113421151	2.10312796943632	3
-3.69495670578880	2.57094380249196	0.132377044582163	3
-5.20439247085754	0.145794978001491	-0.572312138979906	3
-4.72810530704205	2.05068112488441	2.70658082421621	3
-2.82809944575945	4.41325758516104	-0.285639259804059	3
-2.18382728971381	2.23536864069660	0.860236416486809	3
0.721543076891185	5.26843630755271	0.179710695629797	3
-4.68448944514780	2.99428131043640	-0.358505835155200	3
-3.26055022436698	4.67893029724683	2.22132613215009	3
-2.65694046507388	6.19899109353283	0.753256945826532	3
-1.85069972495572	3.15333229794997	1.38966739306352	3
-2.75631298923399	1.90168124899752	-1.19433068110100	3
-2.15348790684050	2.70000585211415	1.63228150316588	3
-3.40884814106376	3.09575541668743	0.463784017237590	3
-4.00347767197370	1.33411934306126	2.84096046517616	3
-3.43957161391909	4.62492806384380	1.85534702202896	3
-2.60316699728023	3.15085878712153	0.519992907110003	3
-3.94795042799786	1.91779361361247	2.51593416009372	3
-1.14306407060308	3.70070469536443	1.21596901482700	3
-2.13302519840315	2.28668775555772	0.613665928158060	3
-0.456669571318446	3.14324821899488	0.570240377119645	3
-3.72361602406472	2.73491185214570	0.581870080466240	3
-3.18031373908985	1.35814096450648	-0.474026255588409	3
-3.38619021553556	4.56734193082096	0.114871941920948	3
-5.84490269414893	0.467126140127510	0.169812581040830	3
-3.98090478192417	0.492296682663036	0.00509513344520152	3
-6.65643257766457	0.610871362880812	1.59794353912121	3
-1.11067535650995	5.01864158905430	1.78102753826668	3
-4.15167872134842	1.50163659161157	0.499347510276062	3
-3.84842880778494	5.15046242290445	1.35496885021300	3
-4.63721720881914	3.81712285808533	0.424309507372978	3
-6.12966736479358	-0.198750290974432	1.65291837802570	3
0.765150889006796	-3.55358507557886	3.50922845626236	4
-0.720715844507684	-4.18652070333418	2.03512430032332	4
-1.03900887529984	-3.21932497874607	4.17198583059134	4
-0.994192694235082	-4.38249720104977	2.83590353088109	4
-0.619291587290169	-2.61824661008290	3.63922614356330	4
-2.52157227603508	-4.84805922909453	2.96905175345156	4
0.497472617362707	-2.01644810971991	2.09167709186029	4
0.816913270641893	-3.35686953504133	1.68114757917309	4
-0.149974227438501	-2.75641408354619	2.38628388173031	4
-1.14218447076923	-3.71994152050411	4.49781710650524	4
1.02810816929935	-3.59249727604219	0.157613170077703	4
-0.478717707000392	-2.74194362758318	1.92256458687541	4
0.788196331489387	-2.40368762141032	1.37114082440931	4
-1.66578933680437	-3.89846197242463	0.442448102675749	4
1.33205985180392	-1.88266967885534	3.80178667597211	4
1.44110565684798	-2.52482376339291	4.04359031133782	4
-0.616726257700424	-2.41879854628638	3.36807781123356	4
-0.294428551889107	-3.59856905171823	4.12900742723789	4
-0.544794027332731	-3.07584766016536	3.50796263891872	4
-2.81929048035817	-5.94829766445072	2.43201483235309	4
1.33331636051282	-1.65467576516620	3.45622366175556	4
-0.174478335770672	-2.49866415093861	1.96350046040459	4
0.869117874102414	-2.81399599498321	1.08836195010404	4
1.08305694404634	-2.10858916106521	0.0815317071208943	4
0.694618078418996	-2.09406088004802	3.50454795031511	4
0.774114388571197	-3.54804433539365	4.73898167869719	4
-0.835208458464087	-4.23598420291490	4.35205077879742	4
-2.27475562937309	-4.83594812143384	6.30229419928684	4
2.10070928664183	-3.07892544150566	2.21151399911145	4
-0.884426161890047	-3.16914978749054	5.29686178523506	4
-4.04190135415458	-5.55803340490242	1.56297500916882	4
2.20390745025205	-1.52287319229727	0.173198256040151	4
-2.55221435668272	-4.60765670908583	2.62363783353327	4
0.428093789093011	-1.96334763094052	3.02833109758407	4
1.12243432231694	-2.48733453858716	3.49296719696341	4
2.33220344767901	-2.22166762864572	4.29360387389903	4
1.04476287579471	-1.91200852243762	3.33363401717380	4
-1.22665131818911	-3.63684214457510	3.90760494237213	4
-0.292947026335167	-3.81610785019978	0.892957764296199	4
-0.508613522812794	-3.64730373329619	2.37953076318429	4
-0.118162211970920	-1.24751418874126	2.53376828765144	4
0.827885413258027	-3.17852722787677	1.85761836514333	4
-1.32120946599840	-3.75521199151584	3.51246081488998	4
-2.63624267644152	-3.95499685610627	5.05682904556104	4
-1.66531824750983	-3.92960774685012	4.01996774258737	4
-2.36491324248881	-3.73270309850160	2.12042697694584	4
-0.357603560321790	-3.14503653300151	0.893716702676865	4
1.54270622788346	-3.20587985962831	2.16703207669618	4
1.29599753802859	-2.84498821121775	3.63426369907787	4
-2.31053132355922	-3.77125461205893	-0.468168553201449	4
3.90643233847813	-0.801587313211536	3.51676510481386	4
-0.0687606551335745	-2.04973264349939	3.83687856051123	4
0.434904101840751	-3.32324418043986	2.13873834693927	4
-0.667709162493078	-3.53384723147716	6.00503457406266	4
-2.53636308239107	-3.35504219430594	2.51297714247467	4
1.11616509449512	-3.35983865569533	4.87751358021832	4
-2.38693051290703	-3.98270070767969	2.00999885540562	4
-1.43182162708173	-4.28375083055211	2.90176624249130	4
-0.124389742785265	-2.05240365803053	2.95928334739365	4
0.946793618432931	-2.08015638120217	1.37590463910991	4
-1.85801457845449	-4.14880160699021	3.93819062450857	4
-0.229903497356306	-2.34391707293308	4.08775618836319	4
-0.814298261208425	-2.27198760934433	3.68117956957402	4
-0.683736687178923	-4.96446986083207	2.34882682377545	4
2.63689862291621	-0.216030357755463	2.03177864141412	4
-0.324148754902210	-3.71497221225087	1.16135570068792	4
0.973437538238595	-2.87963739856514	1.97581684514724	4
-0.820470694934185	-2.61830712387681	1.93964175764496	4
-0.380558983783297	-2.50057231453796	2.74731798184348	4
1.23586727718266	-0.866653428369626	2.24702855223593	4
1.11360441968992	-3.35936278709867	3.09898443428252	4
1.13063156152804	-1.88951921088285	5.66320937891763	4
-1.12497988463671	-3.80568086048409	1.84163066787352	4
0.757409709699232	-2.18278194909850	-0.358528271923340	4
-0.166681618482083	-2.30044325710896	4.16526318290425	4
0.0116823082654330	-3.50710801593278	0.104134944048182	4
1.02453030520208	-2.58544171242681	2.80564732820050	4
0.414250131046115	-3.15690929041373	4.51059850461767	4
1.19386114434319	-3.30638711175454	4.58555961651307	4
0.780005261335646	-2.91165958951020	3.16598377247417	4
1.87150094001271	-2.01978903736524	2.54464144391102	4
-0.439561754856433	-2.21594471986265	3.18600135326228	4
-0.913714341038988	-2.21528156955696	3.68970810993789	4
-0.249824032848876	-2.51430111341078	1.65317401912326	4
0.103777442256180	-2.73753272708219	4.15180338769778	4
1.19324005147759	-2.81002870519776	4.99519867822902	4
-0.917643550254731	-3.25997120404773	2.82213086959837	4
-0.663075301616082	-3.66982459556690	1.40901989936731	4
-2.87851810686916	-4.48182492708991	4.02680127369587	4
-2.12890511402542	-4.50873649593186	2.69794203316502	4
2.22813281755404	-2.38430973514096	3.34993158970401	4
-1.74788390396755	-4.21686713211102	0.644742012856163	4
0.174794977143914	-3.07432186306627	2.91644953420847	4
1.32298056369243	-2.35285215869710	2.57437538044201	4
0.990118643852932	-2.53782769779243	2.81064635018736	4
0.600124191071625	-1.85101033139258	4.05416330122172	4
-0.0967760196414198	-4.21226230416848	2.24114814716840	4
-0.396976481943450	-3.46366659326573	2.99650528372319	4
-0.485960802144072	-2.72985363739582	2.30866094147011	4
-2.01465084778777	-4.14087185077986	2.23256810348066	4
-2.17865514264397	-4.44680003551516	2.10118582466872	4
0.963926321018170	-3.45751277549925	1.75129564916121	4
-0.557996526520347	-3.23381260813215	2.95049391817198	4
-1.23659835212312	-3.37639190992010	1.47977331160717	4
-0.582856668791474	-3.66914965806761	1.87372822344828	4
1.00675649164874	-2.22584775126702	3.02391043995622	4
2.21609797517856	-2.30528160857168	4.56187102866309	4
-2.20134054722955	-4.04963095153435	3.67050791360018	4
-1.29664452484300	-4.29471862586000	1.98178782575738	4
2.32277202602564	-2.06887315464342	4.64131666740505	4
-0.298931764282035	-3.62972358552214	2.55689372378307	4
1.64816183264570	-1.43841392213983	1.73130158006818	4
-0.367112948627741	-3.99177416806065	0.0670818408840961	4
0.707997752729741	-3.06472202223881	1.47060866018998	4
0.402205572099213	-2.95876779195876	0.365276172356610	4
0.412636525528479	-2.35469826701889	3.06147294454164	4
0.0325337036934696	-2.93295394305355	0.927232248680667	4
-1.25502992814249	-4.13029902475207	3.76331494205327	4
1.00453032860667	-2.53333531105143	1.63173646457279	4
-1.42844136055175	-2.84596770235026	2.73704022851764	4

同时数据已存入当前目录的文件“gauss_data.txt”中。

若已知数据与标签后,对其进行作图:

clear
clc
data=dlmread('gauss_data.txt');
data1=data(data(:, end)==1, 1:end-1);
data2=data(data(:, end)==2, 1:end-1);
data3=data(data(:, end)==3, 1:end-1);
data4=data(data(:, end)==4, 1:end-1);
%显示数据
plot3(data1(:,1),data1(:, 2),data1(:,3),'bo');
hold on;
grid on
xlabel('x');
ylabel('y');
zlabel('z');
plot3(data2(:,1),data2(:,2),data2(:,3),'ro');
plot3(data3(:,1),data3(:,2),data3(:,3),'go');
plot3(data4(:,1),data4(:,2),data4(:,3),'ko');

与上面的三维图出来的效果一样。

posted on 2019-05-14 11:00  凯鲁嘎吉  阅读(6021)  评论(0编辑  收藏  举报