-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGMM算法的matlab程序.html
433 lines (431 loc) · 39 KB
/
GMM算法的matlab程序.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<h1 style="text-align: center;">GMM算法的matlab程序</h1>
<p><span style="font-size: 16px;">在“<a id="cb_post_title_url" class="postTitle2" href="https://www.cnblogs.com/kailugaji/p/9920781.html">GMM算法的matlab程序(初步)</a>”这篇文章中已经用matlab程序对iris数据库进行简单的实现,下面的程序最终的目的是求准确度。</span></p>
<p><span style="font-size: 16px;">作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/</span></p>
<h2>1.采用iris数据库</h2>
<h3><span style="font-size: 16px;">iris_data.txt</span></h3>
<div class="cnblogs_code" onclick="cnblogs_code_show('2551d2f0-0dcb-4ce1-b9ca-f97dce36438e')"><img src="http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt="" id="code_img_closed_2551d2f0-0dcb-4ce1-b9ca-f97dce36438e" class="code_img_closed" /><img src="http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="" id="code_img_opened_2551d2f0-0dcb-4ce1-b9ca-f97dce36438e" class="code_img_opened" style="display: none;" />
<div id="cnblogs_code_open_2551d2f0-0dcb-4ce1-b9ca-f97dce36438e" class="cnblogs_code_hide">
<pre><span style="color: #800080;">5.1</span> <span style="color: #800080;">3.5</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.9</span> <span style="color: #800080;">3</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.7</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">1.3</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.6</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5</span> <span style="color: #800080;">3.6</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5.4</span> <span style="color: #800080;">3.9</span> <span style="color: #800080;">1.7</span> <span style="color: #800080;">0.4</span>
<span style="color: #800080;">4.6</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.3</span>
<span style="color: #800080;">5</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.4</span> <span style="color: #800080;">2.9</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.9</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.1</span>
<span style="color: #800080;">5.4</span> <span style="color: #800080;">3.7</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.8</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">1.6</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.8</span> <span style="color: #800080;">3</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.1</span>
<span style="color: #800080;">4.3</span> <span style="color: #800080;">3</span> <span style="color: #800080;">1.1</span> <span style="color: #800080;">0.1</span>
<span style="color: #800080;">5.8</span> <span style="color: #800080;">4</span> <span style="color: #800080;">1.2</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5.7</span> <span style="color: #800080;">4.4</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.4</span>
<span style="color: #800080;">5.4</span> <span style="color: #800080;">3.9</span> <span style="color: #800080;">1.3</span> <span style="color: #800080;">0.4</span>
<span style="color: #800080;">5.1</span> <span style="color: #800080;">3.5</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.3</span>
<span style="color: #800080;">5.7</span> <span style="color: #800080;">3.8</span> <span style="color: #800080;">1.7</span> <span style="color: #800080;">0.3</span>
<span style="color: #800080;">5.1</span> <span style="color: #800080;">3.8</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.3</span>
<span style="color: #800080;">5.4</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">1.7</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5.1</span> <span style="color: #800080;">3.7</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.4</span>
<span style="color: #800080;">4.6</span> <span style="color: #800080;">3.6</span> <span style="color: #800080;">1</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5.1</span> <span style="color: #800080;">3.3</span> <span style="color: #800080;">1.7</span> <span style="color: #800080;">0.5</span>
<span style="color: #800080;">4.8</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">1.9</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5</span> <span style="color: #800080;">3</span> <span style="color: #800080;">1.6</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">1.6</span> <span style="color: #800080;">0.4</span>
<span style="color: #800080;">5.2</span> <span style="color: #800080;">3.5</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5.2</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.7</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">1.6</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.8</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">1.6</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5.4</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.4</span>
<span style="color: #800080;">5.2</span> <span style="color: #800080;">4.1</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.1</span>
<span style="color: #800080;">5.5</span> <span style="color: #800080;">4.2</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.9</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">1.2</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5.5</span> <span style="color: #800080;">3.5</span> <span style="color: #800080;">1.3</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.9</span> <span style="color: #800080;">3.6</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.1</span>
<span style="color: #800080;">4.4</span> <span style="color: #800080;">3</span> <span style="color: #800080;">1.3</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5.1</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5</span> <span style="color: #800080;">3.5</span> <span style="color: #800080;">1.3</span> <span style="color: #800080;">0.3</span>
<span style="color: #800080;">4.5</span> <span style="color: #800080;">2.3</span> <span style="color: #800080;">1.3</span> <span style="color: #800080;">0.3</span>
<span style="color: #800080;">4.4</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">1.3</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5</span> <span style="color: #800080;">3.5</span> <span style="color: #800080;">1.6</span> <span style="color: #800080;">0.6</span>
<span style="color: #800080;">5.1</span> <span style="color: #800080;">3.8</span> <span style="color: #800080;">1.9</span> <span style="color: #800080;">0.4</span>
<span style="color: #800080;">4.8</span> <span style="color: #800080;">3</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.3</span>
<span style="color: #800080;">5.1</span> <span style="color: #800080;">3.8</span> <span style="color: #800080;">1.6</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">4.6</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5.3</span> <span style="color: #800080;">3.7</span> <span style="color: #800080;">1.5</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">5</span> <span style="color: #800080;">3.3</span> <span style="color: #800080;">1.4</span> <span style="color: #800080;">0.2</span>
<span style="color: #800080;">7</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">4.7</span> <span style="color: #800080;">1.4</span>
<span style="color: #800080;">6.4</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">4.5</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">6.9</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">4.9</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">5.5</span> <span style="color: #800080;">2.3</span> <span style="color: #800080;">4</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">6.5</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">4.6</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">5.7</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">4.5</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">6.3</span> <span style="color: #800080;">3.3</span> <span style="color: #800080;">4.7</span> <span style="color: #800080;">1.6</span>
<span style="color: #800080;">4.9</span> <span style="color: #800080;">2.4</span> <span style="color: #800080;">3.3</span> <span style="color: #800080;">1</span>
<span style="color: #800080;">6.6</span> <span style="color: #800080;">2.9</span> <span style="color: #800080;">4.6</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">5.2</span> <span style="color: #800080;">2.7</span> <span style="color: #800080;">3.9</span> <span style="color: #800080;">1.4</span>
<span style="color: #800080;">5</span> <span style="color: #800080;">2</span> <span style="color: #800080;">3.5</span> <span style="color: #800080;">1</span>
<span style="color: #800080;">5.9</span> <span style="color: #800080;">3</span> <span style="color: #800080;">4.2</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">6</span> <span style="color: #800080;">2.2</span> <span style="color: #800080;">4</span> <span style="color: #800080;">1</span>
<span style="color: #800080;">6.1</span> <span style="color: #800080;">2.9</span> <span style="color: #800080;">4.7</span> <span style="color: #800080;">1.4</span>
<span style="color: #800080;">5.6</span> <span style="color: #800080;">2.9</span> <span style="color: #800080;">3.6</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">6.7</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">4.4</span> <span style="color: #800080;">1.4</span>
<span style="color: #800080;">5.6</span> <span style="color: #800080;">3</span> <span style="color: #800080;">4.5</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">5.8</span> <span style="color: #800080;">2.7</span> <span style="color: #800080;">4.1</span> <span style="color: #800080;">1</span>
<span style="color: #800080;">6.2</span> <span style="color: #800080;">2.2</span> <span style="color: #800080;">4.5</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">5.6</span> <span style="color: #800080;">2.5</span> <span style="color: #800080;">3.9</span> <span style="color: #800080;">1.1</span>
<span style="color: #800080;">5.9</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">4.8</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">6.1</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">4</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">6.3</span> <span style="color: #800080;">2.5</span> <span style="color: #800080;">4.9</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">6.1</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">4.7</span> <span style="color: #800080;">1.2</span>
<span style="color: #800080;">6.4</span> <span style="color: #800080;">2.9</span> <span style="color: #800080;">4.3</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">6.6</span> <span style="color: #800080;">3</span> <span style="color: #800080;">4.4</span> <span style="color: #800080;">1.4</span>
<span style="color: #800080;">6.8</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">4.8</span> <span style="color: #800080;">1.4</span>
<span style="color: #800080;">6.7</span> <span style="color: #800080;">3</span> <span style="color: #800080;">5</span> <span style="color: #800080;">1.7</span>
<span style="color: #800080;">6</span> <span style="color: #800080;">2.9</span> <span style="color: #800080;">4.5</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">5.7</span> <span style="color: #800080;">2.6</span> <span style="color: #800080;">3.5</span> <span style="color: #800080;">1</span>
<span style="color: #800080;">5.5</span> <span style="color: #800080;">2.4</span> <span style="color: #800080;">3.8</span> <span style="color: #800080;">1.1</span>
<span style="color: #800080;">5.5</span> <span style="color: #800080;">2.4</span> <span style="color: #800080;">3.7</span> <span style="color: #800080;">1</span>
<span style="color: #800080;">5.8</span> <span style="color: #800080;">2.7</span> <span style="color: #800080;">3.9</span> <span style="color: #800080;">1.2</span>
<span style="color: #800080;">6</span> <span style="color: #800080;">2.7</span> <span style="color: #800080;">5.1</span> <span style="color: #800080;">1.6</span>
<span style="color: #800080;">5.4</span> <span style="color: #800080;">3</span> <span style="color: #800080;">4.5</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">6</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">4.5</span> <span style="color: #800080;">1.6</span>
<span style="color: #800080;">6.7</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">4.7</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">6.3</span> <span style="color: #800080;">2.3</span> <span style="color: #800080;">4.4</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">5.6</span> <span style="color: #800080;">3</span> <span style="color: #800080;">4.1</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">5.5</span> <span style="color: #800080;">2.5</span> <span style="color: #800080;">4</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">5.5</span> <span style="color: #800080;">2.6</span> <span style="color: #800080;">4.4</span> <span style="color: #800080;">1.2</span>
<span style="color: #800080;">6.1</span> <span style="color: #800080;">3</span> <span style="color: #800080;">4.6</span> <span style="color: #800080;">1.4</span>
<span style="color: #800080;">5.8</span> <span style="color: #800080;">2.6</span> <span style="color: #800080;">4</span> <span style="color: #800080;">1.2</span>
<span style="color: #800080;">5</span> <span style="color: #800080;">2.3</span> <span style="color: #800080;">3.3</span> <span style="color: #800080;">1</span>
<span style="color: #800080;">5.6</span> <span style="color: #800080;">2.7</span> <span style="color: #800080;">4.2</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">5.7</span> <span style="color: #800080;">3</span> <span style="color: #800080;">4.2</span> <span style="color: #800080;">1.2</span>
<span style="color: #800080;">5.7</span> <span style="color: #800080;">2.9</span> <span style="color: #800080;">4.2</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">6.2</span> <span style="color: #800080;">2.9</span> <span style="color: #800080;">4.3</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">5.1</span> <span style="color: #800080;">2.5</span> <span style="color: #800080;">3</span> <span style="color: #800080;">1.1</span>
<span style="color: #800080;">5.7</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">4.1</span> <span style="color: #800080;">1.3</span>
<span style="color: #800080;">6.3</span> <span style="color: #800080;">3.3</span> <span style="color: #800080;">6</span> <span style="color: #800080;">2.5</span>
<span style="color: #800080;">5.8</span> <span style="color: #800080;">2.7</span> <span style="color: #800080;">5.1</span> <span style="color: #800080;">1.9</span>
<span style="color: #800080;">7.1</span> <span style="color: #800080;">3</span> <span style="color: #800080;">5.9</span> <span style="color: #800080;">2.1</span>
<span style="color: #800080;">6.3</span> <span style="color: #800080;">2.9</span> <span style="color: #800080;">5.6</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">6.5</span> <span style="color: #800080;">3</span> <span style="color: #800080;">5.8</span> <span style="color: #800080;">2.2</span>
<span style="color: #800080;">7.6</span> <span style="color: #800080;">3</span> <span style="color: #800080;">6.6</span> <span style="color: #800080;">2.1</span>
<span style="color: #800080;">4.9</span> <span style="color: #800080;">2.5</span> <span style="color: #800080;">4.5</span> <span style="color: #800080;">1.7</span>
<span style="color: #800080;">7.3</span> <span style="color: #800080;">2.9</span> <span style="color: #800080;">6.3</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">6.7</span> <span style="color: #800080;">2.5</span> <span style="color: #800080;">5.8</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">7.2</span> <span style="color: #800080;">3.6</span> <span style="color: #800080;">6.1</span> <span style="color: #800080;">2.5</span>
<span style="color: #800080;">6.5</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">5.1</span> <span style="color: #800080;">2</span>
<span style="color: #800080;">6.4</span> <span style="color: #800080;">2.7</span> <span style="color: #800080;">5.3</span> <span style="color: #800080;">1.9</span>
<span style="color: #800080;">6.8</span> <span style="color: #800080;">3</span> <span style="color: #800080;">5.5</span> <span style="color: #800080;">2.1</span>
<span style="color: #800080;">5.7</span> <span style="color: #800080;">2.5</span> <span style="color: #800080;">5</span> <span style="color: #800080;">2</span>
<span style="color: #800080;">5.8</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">5.1</span> <span style="color: #800080;">2.4</span>
<span style="color: #800080;">6.4</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">5.3</span> <span style="color: #800080;">2.3</span>
<span style="color: #800080;">6.5</span> <span style="color: #800080;">3</span> <span style="color: #800080;">5.5</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">7.7</span> <span style="color: #800080;">3.8</span> <span style="color: #800080;">6.7</span> <span style="color: #800080;">2.2</span>
<span style="color: #800080;">7.7</span> <span style="color: #800080;">2.6</span> <span style="color: #800080;">6.9</span> <span style="color: #800080;">2.3</span>
<span style="color: #800080;">6</span> <span style="color: #800080;">2.2</span> <span style="color: #800080;">5</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">6.9</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">5.7</span> <span style="color: #800080;">2.3</span>
<span style="color: #800080;">5.6</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">4.9</span> <span style="color: #800080;">2</span>
<span style="color: #800080;">7.7</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">6.7</span> <span style="color: #800080;">2</span>
<span style="color: #800080;">6.3</span> <span style="color: #800080;">2.7</span> <span style="color: #800080;">4.9</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">6.7</span> <span style="color: #800080;">3.3</span> <span style="color: #800080;">5.7</span> <span style="color: #800080;">2.1</span>
<span style="color: #800080;">7.2</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">6</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">6.2</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">4.8</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">6.1</span> <span style="color: #800080;">3</span> <span style="color: #800080;">4.9</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">6.4</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">5.6</span> <span style="color: #800080;">2.1</span>
<span style="color: #800080;">7.2</span> <span style="color: #800080;">3</span> <span style="color: #800080;">5.8</span> <span style="color: #800080;">1.6</span>
<span style="color: #800080;">7.4</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">6.1</span> <span style="color: #800080;">1.9</span>
<span style="color: #800080;">7.9</span> <span style="color: #800080;">3.8</span> <span style="color: #800080;">6.4</span> <span style="color: #800080;">2</span>
<span style="color: #800080;">6.4</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">5.6</span> <span style="color: #800080;">2.2</span>
<span style="color: #800080;">6.3</span> <span style="color: #800080;">2.8</span> <span style="color: #800080;">5.1</span> <span style="color: #800080;">1.5</span>
<span style="color: #800080;">6.1</span> <span style="color: #800080;">2.6</span> <span style="color: #800080;">5.6</span> <span style="color: #800080;">1.4</span>
<span style="color: #800080;">7.7</span> <span style="color: #800080;">3</span> <span style="color: #800080;">6.1</span> <span style="color: #800080;">2.3</span>
<span style="color: #800080;">6.3</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">5.6</span> <span style="color: #800080;">2.4</span>
<span style="color: #800080;">6.4</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">5.5</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">6</span> <span style="color: #800080;">3</span> <span style="color: #800080;">4.8</span> <span style="color: #800080;">1.8</span>
<span style="color: #800080;">6.9</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">5.4</span> <span style="color: #800080;">2.1</span>
<span style="color: #800080;">6.7</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">5.6</span> <span style="color: #800080;">2.4</span>
<span style="color: #800080;">6.9</span> <span style="color: #800080;">3.1</span> <span style="color: #800080;">5.1</span> <span style="color: #800080;">2.3</span>
<span style="color: #800080;">5.8</span> <span style="color: #800080;">2.7</span> <span style="color: #800080;">5.1</span> <span style="color: #800080;">1.9</span>
<span style="color: #800080;">6.8</span> <span style="color: #800080;">3.2</span> <span style="color: #800080;">5.9</span> <span style="color: #800080;">2.3</span>
<span style="color: #800080;">6.7</span> <span style="color: #800080;">3.3</span> <span style="color: #800080;">5.7</span> <span style="color: #800080;">2.5</span>
<span style="color: #800080;">6.7</span> <span style="color: #800080;">3</span> <span style="color: #800080;">5.2</span> <span style="color: #800080;">2.3</span>
<span style="color: #800080;">6.3</span> <span style="color: #800080;">2.5</span> <span style="color: #800080;">5</span> <span style="color: #800080;">1.9</span>
<span style="color: #800080;">6.5</span> <span style="color: #800080;">3</span> <span style="color: #800080;">5.2</span> <span style="color: #800080;">2</span>
<span style="color: #800080;">6.2</span> <span style="color: #800080;">3.4</span> <span style="color: #800080;">5.4</span> <span style="color: #800080;">2.3</span>
<span style="color: #800080;">5.9</span> <span style="color: #800080;">3</span> <span style="color: #800080;">5.1</span> <span style="color: #800080;">1.8</span></pre>
</div>
<span class="cnblogs_code_collapse">View Code</span></div>
<h3><span style="font-size: 16px;">iris_id.txt</span></h3>
<div class="cnblogs_code" onclick="cnblogs_code_show('18fc630b-bc05-47df-8081-ea2ee7fbc9b7')"><img src="http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt="" id="code_img_closed_18fc630b-bc05-47df-8081-ea2ee7fbc9b7" class="code_img_closed" /><img src="http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="" id="code_img_opened_18fc630b-bc05-47df-8081-ea2ee7fbc9b7" class="code_img_opened" style="display: none;" />
<div id="cnblogs_code_open_18fc630b-bc05-47df-8081-ea2ee7fbc9b7" class="cnblogs_code_hide">
<pre><span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">0</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">1</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span>
<span style="color: #800080;">2</span></pre>
</div>
<span class="cnblogs_code_collapse">View Code</span></div>
<h2>2.matlab程序</h2>
<h3><span style="font-size: 16px;">My_GMM.m</span></h3>
<div class="cnblogs_Highlighter">
<pre class="brush:matlab;gutter:true;">function label_2=My_GMM(K)
%输入K:聚类数,K个单高斯模型
%输出label_2:聚的类,para_pi:单高斯权重,para_miu_new:高斯分布参数μ,para_sigma:高斯分布参数sigma
format long
eps=1e-15; %定义迭代终止条件的eps
data=dlmread('E:\www.cnblogs.comkailugaji\data\iris\iris_data.txt');
%----------------------------------------------------------------------------------------------------
%对data做最大-最小归一化处理
[data_num,~]=size(data);
X=(data-ones(data_num,1)*min(data))./(ones(data_num,1)*(max(data)-min(data)));
[X_num,X_dim]=size(X);
para_sigma=zeros(X_dim,X_dim,K);
%----------------------------------------------------------------------------------------------------
%随机初始化K个聚类中心
rand_array=randperm(X_num); %产生1~X_num之间整数的随机排列
center=X(rand_array(1:K),:); %随机排列取前K个数,在X矩阵中取这K行作为初始聚类中心
%根据上述聚类中心初始化参数
para_miu_new=center; %初始化参数miu
para_pi=ones(1,K)./K; %K类单高斯模型的权重
for k=1:K
para_sigma(:,:,k)=eye(X_dim); %K类单高斯模型的协方差矩阵,初始化为单位阵
end
%欧氏距离,计算(X-para_miu)^2=X^2+para_miu^2-2*X*para_miu',矩阵大小为X_num*K
distant=repmat(sum(X.*X,2),1,K)+repmat(sum(para_miu_new.*para_miu_new,2)',X_num,1)-2*X*para_miu_new';
%返回distant每行最小值所在的下标
[~,label_1]=min(distant,[],2);
for k=1:K
X_k=X(label_1==k,:); %X_k是一个(X_num/K, X_dim)的矩阵,把X矩阵分为K类
para_pi(k)=size(X_k,1)/X_num; %将(每一类数据的个数/X_num)作为para_pi的初始值
para_sigma(:,:,k)=cov(X_k); %para_sigma是一个(X_dim, X_dim)的矩阵,cov(矩阵)求的是每一列之间的协方差
end
%----------------------------------------------------------------------------------------------------
%EM算法
N_pdf=zeros(X_num,K);
while true
para_miu=para_miu_new;
%----------------------------------------------------------------------------------------------------
%E步
%单高斯分布的概率密度函数N_pdf
for k=1:K
X_miu=X-repmat(para_miu(k,:),X_num,1); %X-miu,(X_num, X_dim)的矩阵
sigma_inv=inv(para_sigma(:,:,k)); %sigma的逆矩阵,(X_dim, X_dim)的矩阵//很可能出现奇异矩阵
exp_up=sum((X_miu*sigma_inv).*X_miu,2); %指数的幂,(X-miu)'*sigma^(-1)*(X-miu)
coefficient=(2*pi)^(-X_dim/2)*sqrt(det(sigma_inv)); %高斯分布的概率密度函数e左边的系数
N_pdf(:,k)=coefficient*exp(-0.5*exp_up);
end
% N_pdf=guass_pdf(X,K,para_miu,para_sigma);
responsivity=N_pdf.*repmat(para_pi,X_num,1); %响应度responsivity的分子,(X_num,K)的矩阵
responsivity=responsivity./repmat(sum(responsivity,2),1,K); %responsivity:在当前模型下第n个观测数据来自第k个分模型的概率,即分模型k对观测数据Xn的响应度
%----------------------------------------------------------------------------------------------------
%M步
R_k=sum(responsivity,1); %(1,K)的矩阵,把responsivity每一列求和
%更新参数miu
para_miu_new=diag(1./R_k)*responsivity'*X;
%更新k个参数sigma
for i=1:K
X_miu=X-repmat(para_miu_new(i,:),X_num,1);
para_sigma(:,:,i)=(X_miu'*(diag(responsivity(:,i))*X_miu))/R_k(i);
end
%更新参数pi
para_pi=R_k/sum(R_k);
%----------------------------------------------------------------------------------------------------
%迭代终止条件
if norm(para_miu_new-para_miu)<=eps
break;
end
end
%----------------------------------------------------------------------------------------------------
%聚类
[~,label_2]=max(responsivity,[],2);</pre>
</div>
<h3><span style="font-size: 16px;">succeed.m</span></h3>
<div class="cnblogs_Highlighter">
<pre class="brush:matlab;gutter:true;">function accuracy=succeed(K,id)
%输入K:聚的类,id:训练后的聚类结果,N*1的矩阵
N=size(id,1); %样本个数
p=perms(1:K); %全排列矩阵
p_col=size(p,1); %全排列的行数
new_label=zeros(N,p_col); %聚类结果的所有可能取值,N*p_col
num=zeros(1,p_col); %与真实聚类结果一样的个数
real_label=dlmread('E:\www.cnblogs.comkailugaji\data\iris\iris_id.txt');
%将训练结果全排列为N*p_col的矩阵,每一列为一种可能性
for i=1:N
for j=1:p_col
for k=1:K
if id(i)==k
new_label(i,j)=p(j,k)-1;
end
end
end
end
%与真实结果比对,计算精确度
for j=1:p_col
for i=1:N
if new_label(i,j)==real_label(i)
num(j)=num(j)+1;
end
end
end
accuracy=max(num)/N;
</pre>
</div>
<h2>3.结果</h2>
<div class="cnblogs_Highlighter">
<pre class="brush:matlab;gutter:true;">>> label_1=My_GMM(3);
>> accuracy=succeed(3,label_1)
accuracy =
0.966666666666667</pre>
</div>
<h2>4.注意</h2>
<p> <span style="font-size: 16px;"> GMM算法我只进行了一次计算准确度,因为有可能会出现奇异矩阵的情况,导致算法出错,现在我还没有想出如何解决奇异矩阵的问题,因此只给出了一次循环。望指正。</span></p>
<p><span style="font-size: 16px;"> 2020.7.30 奇异问题已初步解决,见评论链接。</span></p>
<p><span style="font-size: 18px; font-family: 'times new roman', times;">补充:GMM的Python代码:<a href="https://github.com/wl-lei/upload/blob/master/homework/GMM.py" target="_blank">upload/GMM.py at master · wl-lei/upload · GitHub</a></span></p>
<p><span style="font-size: 18px; font-family: 'times new roman', times;"> GMM的MATLAB代码:<a href="https://github.com/kailugaji/Gaussian_Mixture_Model_for_Clustering" target="_blank">https://github.com/kailugaji/Gaussian_Mixture_Model_for_Clustering</a> (<span style="color: #ff6600;">注意!!!</span>:我完善了GMM程序,比这篇博客的代码更加完善,放到了GitHub里面,进一步了解GMM代码请移步GitHub)<a href="https://github.com/kailugaji/GaussianMixtureModel-clustering" target="_blank"><br /></a></span></p>