-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathsklearn.cluster.SpectralClustering.html
635 lines (595 loc) · 49.2 KB
/
sklearn.cluster.SpectralClustering.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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta property="og:title" content="sklearn.cluster.SpectralClustering" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://scikit-learn/stable/modules/generated/sklearn.cluster.SpectralClustering.html" />
<meta property="og:site_name" content="scikit-learn" />
<meta property="og:description" content="Examples using sklearn.cluster.SpectralClustering: Comparing different clustering algorithms on toy datasets" />
<meta property="og:image" content="https://scikit-learn/stable/_images/sphx_glr_plot_cluster_comparison_thumb.png" />
<meta property="og:image:alt" content="" />
<meta name="description" content="Examples using sklearn.cluster.SpectralClustering: Comparing different clustering algorithms on toy datasets" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>sklearn.cluster.SpectralClustering — scikit-learn 1.3.2 documentation</title>
<link rel="canonical" href="http://scikit-learn.org/stable/modules/generated/sklearn.cluster.SpectralClustering.html" />
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<link rel="stylesheet" href="../../_static/css/vendor/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/copybutton.css" type="text/css" />
<link rel="stylesheet" href="../../_static/plot_directive.css" type="text/css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Vibur" type="text/css" />
<link rel="stylesheet" href="../../_static/jupyterlite_sphinx.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sg_gallery.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sg_gallery-binder.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sg_gallery-dataframe.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sg_gallery-rendered-html.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<script id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/js/vendor/jquery-3.6.3.slim.min.js"></script>
</head>
<body>
<nav id="navbar" class="sk-docs-navbar navbar navbar-expand-md navbar-light bg-light py-0">
<div class="container-fluid sk-docs-container px-0">
<a class="navbar-brand py-0" href="../../index.html">
<img
class="sk-brand-img"
src="../../_static/scikit-learn-logo-small.png"
alt="logo"/>
</a>
<button
id="sk-navbar-toggler"
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="sk-navbar-collapse collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="sk-nav-link nav-link" href="../../install.html">Install</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link" href="../../user_guide.html">User Guide</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link" href="../classes.html">API</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link" href="../../auto_examples/index.html">Examples</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link" target="_blank" rel="noopener noreferrer" href="https://blog.scikit-learn.org/">Community</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../getting_started.html" >Getting Started</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../tutorial/index.html" >Tutorial</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../whats_new/v1.3.html" >What's new</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../glossary.html" >Glossary</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://scikit-learn.org/dev/developers/index.html" target="_blank" rel="noopener noreferrer">Development</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../faq.html" >FAQ</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../support.html" >Support</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../related_projects.html" >Related packages</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../roadmap.html" >Roadmap</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../governance.html" >Governance</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../about.html" >About us</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://github.com/scikit-learn/scikit-learn" >GitHub</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://scikit-learn.org/dev/versions.html" >Other Versions and Download</a>
</li>
<li class="nav-item dropdown nav-more-item-dropdown">
<a class="sk-nav-link nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">More</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="sk-nav-dropdown-item dropdown-item" href="../../getting_started.html" >Getting Started</a>
<a class="sk-nav-dropdown-item dropdown-item" href="../../tutorial/index.html" >Tutorial</a>
<a class="sk-nav-dropdown-item dropdown-item" href="../../whats_new/v1.3.html" >What's new</a>
<a class="sk-nav-dropdown-item dropdown-item" href="../../glossary.html" >Glossary</a>
<a class="sk-nav-dropdown-item dropdown-item" href="https://scikit-learn.org/dev/developers/index.html" target="_blank" rel="noopener noreferrer">Development</a>
<a class="sk-nav-dropdown-item dropdown-item" href="../../faq.html" >FAQ</a>
<a class="sk-nav-dropdown-item dropdown-item" href="../../support.html" >Support</a>
<a class="sk-nav-dropdown-item dropdown-item" href="../../related_projects.html" >Related packages</a>
<a class="sk-nav-dropdown-item dropdown-item" href="../../roadmap.html" >Roadmap</a>
<a class="sk-nav-dropdown-item dropdown-item" href="../../governance.html" >Governance</a>
<a class="sk-nav-dropdown-item dropdown-item" href="../../about.html" >About us</a>
<a class="sk-nav-dropdown-item dropdown-item" href="https://github.com/scikit-learn/scikit-learn" >GitHub</a>
<a class="sk-nav-dropdown-item dropdown-item" href="https://scikit-learn.org/dev/versions.html" >Other Versions and Download</a>
</div>
</li>
</ul>
<div id="searchbox" role="search">
<div class="searchformwrapper">
<form class="search" action="../../search.html" method="get">
<input class="sk-search-text-input" type="text" name="q" aria-labelledby="searchlabel" />
<input class="sk-search-text-btn" type="submit" value="Go" />
</form>
</div>
</div>
</div>
</div>
</nav>
<div class="d-flex" id="sk-doc-wrapper">
<input type="checkbox" name="sk-toggle-checkbox" id="sk-toggle-checkbox">
<label id="sk-sidemenu-toggle" class="sk-btn-toggle-toc btn sk-btn-primary" for="sk-toggle-checkbox">Toggle Menu</label>
<div id="sk-sidebar-wrapper" class="border-right">
<div class="sk-sidebar-toc-wrapper">
<div class="btn-group w-100 mb-2" role="group" aria-label="rellinks">
<a href="sklearn.cluster.OPTICS.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="sklearn.cluster.OPTICS">Prev</a><a href="../classes.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="API Reference">Up</a>
<a href="sklearn.cluster.SpectralBiclustering.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="sklearn.cluster.SpectralBiclustering">Next</a>
</div>
<div class="alert alert-danger p-1 mb-2" role="alert">
<p class="text-center mb-0">
<strong>scikit-learn 1.3.2</strong><br/>
<a href="http://scikit-learn.org/dev/versions.html">Other versions</a>
</p>
</div>
<div class="alert alert-warning p-1 mb-2" role="alert">
<p class="text-center mb-0">
Please <a class="font-weight-bold" href="../../about.html#citing-scikit-learn"><string>cite us</string></a> if you use the software.
</p>
</div>
<div class="sk-sidebar-toc">
<ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sklearn.cluster</span></code>.SpectralClustering</a><ul>
<li><a class="reference internal" href="#sklearn.cluster.SpectralClustering"><code class="docutils literal notranslate"><span class="pre">SpectralClustering</span></code></a><ul>
<li><a class="reference internal" href="#sklearn.cluster.SpectralClustering.fit"><code class="docutils literal notranslate"><span class="pre">SpectralClustering.fit</span></code></a></li>
<li><a class="reference internal" href="#sklearn.cluster.SpectralClustering.fit_predict"><code class="docutils literal notranslate"><span class="pre">SpectralClustering.fit_predict</span></code></a></li>
<li><a class="reference internal" href="#sklearn.cluster.SpectralClustering.get_metadata_routing"><code class="docutils literal notranslate"><span class="pre">SpectralClustering.get_metadata_routing</span></code></a></li>
<li><a class="reference internal" href="#sklearn.cluster.SpectralClustering.get_params"><code class="docutils literal notranslate"><span class="pre">SpectralClustering.get_params</span></code></a></li>
<li><a class="reference internal" href="#sklearn.cluster.SpectralClustering.set_params"><code class="docutils literal notranslate"><span class="pre">SpectralClustering.set_params</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#examples-using-sklearn-cluster-spectralclustering">Examples using <code class="docutils literal notranslate"><span class="pre">sklearn.cluster.SpectralClustering</span></code></a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div id="sk-page-content-wrapper">
<div class="sk-page-content container-fluid body px-md-3" role="main">
<section id="sklearn-cluster-spectralclustering">
<h1><a class="reference internal" href="../classes.html#module-sklearn.cluster" title="sklearn.cluster"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sklearn.cluster</span></code></a>.SpectralClustering<a class="headerlink" href="#sklearn-cluster-spectralclustering" title="Permalink to this heading">¶</a></h1>
<dl class="py class">
<dt class="sig sig-object py" id="sklearn.cluster.SpectralClustering">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">sklearn.cluster.</span></span><span class="sig-name descname"><span class="pre">SpectralClustering</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n_clusters</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">8</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eigen_solver</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n_components</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">random_state</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n_init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gamma</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">affinity</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'rbf'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n_neighbors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eigen_tol</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'auto'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_labels</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'kmeans'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">degree</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">coef0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">kernel_params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n_jobs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">verbose</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/3f89022fa/sklearn/cluster/_spectral.py#L366"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sklearn.cluster.SpectralClustering" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply clustering to a projection of the normalized Laplacian.</p>
<p>In practice Spectral Clustering is very useful when the structure of
the individual clusters is highly non-convex, or more generally when
a measure of the center and spread of the cluster is not a suitable
description of the complete cluster, such as when clusters are
nested circles on the 2D plane.</p>
<p>If the affinity matrix is the adjacency matrix of a graph, this method
can be used to find normalized graph cuts <a class="reference internal" href="#r5f6cbeb1558e-1" id="id1">[1]</a>, <a class="reference internal" href="#r5f6cbeb1558e-2" id="id2">[2]</a>.</p>
<p>When calling <code class="docutils literal notranslate"><span class="pre">fit</span></code>, an affinity matrix is constructed using either
a kernel function such the Gaussian (aka RBF) kernel with Euclidean
distance <code class="docutils literal notranslate"><span class="pre">d(X,</span> <span class="pre">X)</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">gamma</span> <span class="o">*</span> <span class="n">d</span><span class="p">(</span><span class="n">X</span><span class="p">,</span><span class="n">X</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
<p>or a k-nearest neighbors connectivity matrix.</p>
<p>Alternatively, a user-provided affinity matrix can be specified by
setting <code class="docutils literal notranslate"><span class="pre">affinity='precomputed'</span></code>.</p>
<p>Read more in the <a class="reference internal" href="../clustering.html#spectral-clustering"><span class="std std-ref">User Guide</span></a>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><dl>
<dt><strong>n_clusters</strong><span class="classifier">int, default=8</span></dt><dd><p>The dimension of the projection subspace.</p>
</dd>
<dt><strong>eigen_solver</strong><span class="classifier">{‘arpack’, ‘lobpcg’, ‘amg’}, default=None</span></dt><dd><p>The eigenvalue decomposition strategy to use. AMG requires pyamg
to be installed. It can be faster on very large, sparse problems,
but may also lead to instabilities. If None, then <code class="docutils literal notranslate"><span class="pre">'arpack'</span></code> is
used. See <a class="reference internal" href="#r5f6cbeb1558e-4" id="id3">[4]</a> for more details regarding <code class="docutils literal notranslate"><span class="pre">'lobpcg'</span></code>.</p>
</dd>
<dt><strong>n_components</strong><span class="classifier">int, default=None</span></dt><dd><p>Number of eigenvectors to use for the spectral embedding. If None,
defaults to <code class="docutils literal notranslate"><span class="pre">n_clusters</span></code>.</p>
</dd>
<dt><strong>random_state</strong><span class="classifier">int, RandomState instance, default=None</span></dt><dd><p>A pseudo random number generator used for the initialization
of the lobpcg eigenvectors decomposition when <code class="docutils literal notranslate"><span class="pre">eigen_solver</span> <span class="pre">==</span>
<span class="pre">'amg'</span></code>, and for the K-Means initialization. Use an int to make
the results deterministic across calls (See
<a class="reference internal" href="../../glossary.html#term-random_state"><span class="xref std std-term">Glossary</span></a>).</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>When using <code class="docutils literal notranslate"><span class="pre">eigen_solver</span> <span class="pre">==</span> <span class="pre">'amg'</span></code>,
it is necessary to also fix the global numpy seed with
<code class="docutils literal notranslate"><span class="pre">np.random.seed(int)</span></code> to get deterministic results. See
<a class="reference external" href="https://github.com/pyamg/pyamg/issues/139">https://github.com/pyamg/pyamg/issues/139</a> for further
information.</p>
</div>
</dd>
<dt><strong>n_init</strong><span class="classifier">int, default=10</span></dt><dd><p>Number of time the k-means algorithm will be run with different
centroid seeds. The final results will be the best output of n_init
consecutive runs in terms of inertia. Only used if
<code class="docutils literal notranslate"><span class="pre">assign_labels='kmeans'</span></code>.</p>
</dd>
<dt><strong>gamma</strong><span class="classifier">float, default=1.0</span></dt><dd><p>Kernel coefficient for rbf, poly, sigmoid, laplacian and chi2 kernels.
Ignored for <code class="docutils literal notranslate"><span class="pre">affinity='nearest_neighbors'</span></code>.</p>
</dd>
<dt><strong>affinity</strong><span class="classifier">str or callable, default=’rbf’</span></dt><dd><dl class="simple">
<dt>How to construct the affinity matrix.</dt><dd><ul class="simple">
<li><p>‘nearest_neighbors’: construct the affinity matrix by computing a
graph of nearest neighbors.</p></li>
<li><p>‘rbf’: construct the affinity matrix using a radial basis function
(RBF) kernel.</p></li>
<li><p>‘precomputed’: interpret <code class="docutils literal notranslate"><span class="pre">X</span></code> as a precomputed affinity matrix,
where larger values indicate greater similarity between instances.</p></li>
<li><p>‘precomputed_nearest_neighbors’: interpret <code class="docutils literal notranslate"><span class="pre">X</span></code> as a sparse graph
of precomputed distances, and construct a binary affinity matrix
from the <code class="docutils literal notranslate"><span class="pre">n_neighbors</span></code> nearest neighbors of each instance.</p></li>
<li><p>one of the kernels supported by
<a class="reference internal" href="sklearn.metrics.pairwise.pairwise_kernels.html#sklearn.metrics.pairwise.pairwise_kernels" title="sklearn.metrics.pairwise.pairwise_kernels"><code class="xref py py-func docutils literal notranslate"><span class="pre">pairwise_kernels</span></code></a>.</p></li>
</ul>
</dd>
</dl>
<p>Only kernels that produce similarity scores (non-negative values that
increase with similarity) should be used. This property is not checked
by the clustering algorithm.</p>
</dd>
<dt><strong>n_neighbors</strong><span class="classifier">int, default=10</span></dt><dd><p>Number of neighbors to use when constructing the affinity matrix using
the nearest neighbors method. Ignored for <code class="docutils literal notranslate"><span class="pre">affinity='rbf'</span></code>.</p>
</dd>
<dt><strong>eigen_tol</strong><span class="classifier">float, default=”auto”</span></dt><dd><p>Stopping criterion for eigen decomposition of the Laplacian matrix.
If <code class="docutils literal notranslate"><span class="pre">eigen_tol="auto"</span></code> then the passed tolerance will depend on the
<code class="docutils literal notranslate"><span class="pre">eigen_solver</span></code>:</p>
<ul class="simple">
<li><p>If <code class="docutils literal notranslate"><span class="pre">eigen_solver="arpack"</span></code>, then <code class="docutils literal notranslate"><span class="pre">eigen_tol=0.0</span></code>;</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">eigen_solver="lobpcg"</span></code> or <code class="docutils literal notranslate"><span class="pre">eigen_solver="amg"</span></code>, then
<code class="docutils literal notranslate"><span class="pre">eigen_tol=None</span></code> which configures the underlying <code class="docutils literal notranslate"><span class="pre">lobpcg</span></code> solver to
automatically resolve the value according to their heuristics. See,
<a class="reference external" href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.lobpcg.html#scipy.sparse.linalg.lobpcg" title="(in SciPy v1.11.3)"><code class="xref py py-func docutils literal notranslate"><span class="pre">scipy.sparse.linalg.lobpcg</span></code></a> for details.</p></li>
</ul>
<p>Note that when using <code class="docutils literal notranslate"><span class="pre">eigen_solver="lobpcg"</span></code> or <code class="docutils literal notranslate"><span class="pre">eigen_solver="amg"</span></code>
values of <code class="docutils literal notranslate"><span class="pre">tol<1e-5</span></code> may lead to convergence issues and should be
avoided.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 1.2: </span>Added ‘auto’ option.</p>
</div>
</dd>
<dt><strong>assign_labels</strong><span class="classifier">{‘kmeans’, ‘discretize’, ‘cluster_qr’}, default=’kmeans’</span></dt><dd><p>The strategy for assigning labels in the embedding space. There are two
ways to assign labels after the Laplacian embedding. k-means is a
popular choice, but it can be sensitive to initialization.
Discretization is another approach which is less sensitive to random
initialization <a class="reference internal" href="#r5f6cbeb1558e-3" id="id4">[3]</a>.
The cluster_qr method <a class="reference internal" href="#r5f6cbeb1558e-5" id="id5">[5]</a> directly extract clusters from eigenvectors
in spectral clustering. In contrast to k-means and discretization, cluster_qr
has no tuning parameters and runs no iterations, yet may outperform
k-means and discretization in terms of both quality and speed.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 1.1: </span>Added new labeling method ‘cluster_qr’.</p>
</div>
</dd>
<dt><strong>degree</strong><span class="classifier">float, default=3</span></dt><dd><p>Degree of the polynomial kernel. Ignored by other kernels.</p>
</dd>
<dt><strong>coef0</strong><span class="classifier">float, default=1</span></dt><dd><p>Zero coefficient for polynomial and sigmoid kernels.
Ignored by other kernels.</p>
</dd>
<dt><strong>kernel_params</strong><span class="classifier">dict of str to any, default=None</span></dt><dd><p>Parameters (keyword arguments) and values for kernel passed as
callable object. Ignored by other kernels.</p>
</dd>
<dt><strong>n_jobs</strong><span class="classifier">int, default=None</span></dt><dd><p>The number of parallel jobs to run when <code class="docutils literal notranslate"><span class="pre">affinity='nearest_neighbors'</span></code>
or <code class="docutils literal notranslate"><span class="pre">affinity='precomputed_nearest_neighbors'</span></code>. The neighbors search
will be done in parallel.
<code class="docutils literal notranslate"><span class="pre">None</span></code> means 1 unless in a <a class="reference external" href="https://joblib.readthedocs.io/en/latest/generated/joblib.parallel_backend.html#joblib.parallel_backend" title="(in joblib v1.4.dev0)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">joblib.parallel_backend</span></code></a> context.
<code class="docutils literal notranslate"><span class="pre">-1</span></code> means using all processors. See <a class="reference internal" href="../../glossary.html#term-n_jobs"><span class="xref std std-term">Glossary</span></a>
for more details.</p>
</dd>
<dt><strong>verbose</strong><span class="classifier">bool, default=False</span></dt><dd><p>Verbosity mode.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 0.24.</span></p>
</div>
</dd>
</dl>
</dd>
<dt class="field-even">Attributes<span class="colon">:</span></dt>
<dd class="field-even"><dl>
<dt><strong>affinity_matrix_</strong><span class="classifier">array-like of shape (n_samples, n_samples)</span></dt><dd><p>Affinity matrix used for clustering. Available only after calling
<code class="docutils literal notranslate"><span class="pre">fit</span></code>.</p>
</dd>
<dt><strong>labels_</strong><span class="classifier">ndarray of shape (n_samples,)</span></dt><dd><p>Labels of each point</p>
</dd>
<dt><strong>n_features_in_</strong><span class="classifier">int</span></dt><dd><p>Number of features seen during <a class="reference internal" href="../../glossary.html#term-fit"><span class="xref std std-term">fit</span></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 0.24.</span></p>
</div>
</dd>
<dt><strong>feature_names_in_</strong><span class="classifier">ndarray of shape (<code class="docutils literal notranslate"><span class="pre">n_features_in_</span></code>,)</span></dt><dd><p>Names of features seen during <a class="reference internal" href="../../glossary.html#term-fit"><span class="xref std std-term">fit</span></a>. Defined only when <code class="docutils literal notranslate"><span class="pre">X</span></code>
has feature names that are all strings.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 1.0.</span></p>
</div>
</dd>
</dl>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="sklearn.cluster.KMeans.html#sklearn.cluster.KMeans" title="sklearn.cluster.KMeans"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sklearn.cluster.KMeans</span></code></a></dt><dd><p>K-Means clustering.</p>
</dd>
<dt><a class="reference internal" href="sklearn.cluster.DBSCAN.html#sklearn.cluster.DBSCAN" title="sklearn.cluster.DBSCAN"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sklearn.cluster.DBSCAN</span></code></a></dt><dd><p>Density-Based Spatial Clustering of Applications with Noise.</p>
</dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>A distance matrix for which 0 indicates identical elements and high values
indicate very dissimilar elements can be transformed into an affinity /
similarity matrix that is well-suited for the algorithm by
applying the Gaussian (aka RBF, heat) kernel:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span> <span class="n">dist_matrix</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">/</span> <span class="p">(</span><span class="mf">2.</span> <span class="o">*</span> <span class="n">delta</span> <span class="o">**</span> <span class="mi">2</span><span class="p">))</span>
</pre></div>
</div>
<p>where <code class="docutils literal notranslate"><span class="pre">delta</span></code> is a free parameter representing the width of the Gaussian
kernel.</p>
<p>An alternative is to take a symmetric version of the k-nearest neighbors
connectivity matrix of the points.</p>
<p>If the pyamg package is installed, it is used: this greatly
speeds up computation.</p>
<p class="rubric">References</p>
<div role="list" class="citation-list">
<div class="citation" id="r5f6cbeb1558e-1" role="doc-biblioentry">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id1">1</a><span class="fn-bracket">]</span></span>
<p><a class="reference external" href="https://doi.org/10.1109/34.868688">Normalized cuts and image segmentation, 2000
Jianbo Shi, Jitendra Malik</a></p>
</div>
<div class="citation" id="r5f6cbeb1558e-2" role="doc-biblioentry">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id2">2</a><span class="fn-bracket">]</span></span>
<p><a class="reference external" href="https://doi.org/10.1007/s11222-007-9033-z">A Tutorial on Spectral Clustering, 2007
Ulrike von Luxburg</a></p>
</div>
<div class="citation" id="r5f6cbeb1558e-3" role="doc-biblioentry">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id4">3</a><span class="fn-bracket">]</span></span>
<p><a class="reference external" href="https://people.eecs.berkeley.edu/~jordan/courses/281B-spring04/readings/yu-shi.pdf">Multiclass spectral clustering, 2003
Stella X. Yu, Jianbo Shi</a></p>
</div>
<div class="citation" id="r5f6cbeb1558e-4" role="doc-biblioentry">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id3">4</a><span class="fn-bracket">]</span></span>
<p><a class="reference external" href="https://doi.org/10.1137/S1064827500366124">Toward the Optimal Preconditioned Eigensolver:
Locally Optimal Block Preconditioned Conjugate Gradient Method, 2001
A. V. Knyazev
SIAM Journal on Scientific Computing 23, no. 2, pp. 517-541.</a></p>
</div>
<div class="citation" id="r5f6cbeb1558e-5" role="doc-biblioentry">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id5">5</a><span class="fn-bracket">]</span></span>
<p><a class="reference external" href="https://doi.org/10.1093/imaiai/iay008">Simple, direct, and efficient multi-way spectral clustering, 2019
Anil Damle, Victor Minden, Lexing Ying</a></p>
</div>
</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">sklearn.cluster</span> <span class="kn">import</span> <span class="n">SpectralClustering</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">>>> </span><span class="n">X</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
<span class="gp">... </span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">7</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="n">clustering</span> <span class="o">=</span> <span class="n">SpectralClustering</span><span class="p">(</span><span class="n">n_clusters</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">assign_labels</span><span class="o">=</span><span class="s1">'discretize'</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">clustering</span><span class="o">.</span><span class="n">labels_</span>
<span class="go">array([1, 1, 1, 0, 0, 0])</span>
<span class="gp">>>> </span><span class="n">clustering</span>
<span class="go">SpectralClustering(assign_labels='discretize', n_clusters=2,</span>
<span class="go"> random_state=0)</span>
</pre></div>
</div>
<p class="rubric">Methods</p>
<table class="autosummary longtable docutils align-default">
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="#sklearn.cluster.SpectralClustering.fit" title="sklearn.cluster.SpectralClustering.fit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fit</span></code></a>(X[, y])</p></td>
<td><p>Perform spectral clustering from features, or affinity matrix.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sklearn.cluster.SpectralClustering.fit_predict" title="sklearn.cluster.SpectralClustering.fit_predict"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fit_predict</span></code></a>(X[, y])</p></td>
<td><p>Perform spectral clustering on <code class="docutils literal notranslate"><span class="pre">X</span></code> and return cluster labels.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#sklearn.cluster.SpectralClustering.get_metadata_routing" title="sklearn.cluster.SpectralClustering.get_metadata_routing"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_metadata_routing</span></code></a>()</p></td>
<td><p>Get metadata routing of this object.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sklearn.cluster.SpectralClustering.get_params" title="sklearn.cluster.SpectralClustering.get_params"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_params</span></code></a>([deep])</p></td>
<td><p>Get parameters for this estimator.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#sklearn.cluster.SpectralClustering.set_params" title="sklearn.cluster.SpectralClustering.set_params"><code class="xref py py-obj docutils literal notranslate"><span class="pre">set_params</span></code></a>(**params)</p></td>
<td><p>Set the parameters of this estimator.</p></td>
</tr>
</tbody>
</table>
<dl class="py method">
<dt class="sig sig-object py" id="sklearn.cluster.SpectralClustering.fit">
<span class="sig-name descname"><span class="pre">fit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">y</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/3f89022fa/sklearn/cluster/_spectral.py#L654"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sklearn.cluster.SpectralClustering.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform spectral clustering from features, or affinity matrix.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>X</strong><span class="classifier">{array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)</span></dt><dd><p>Training instances to cluster, similarities / affinities between
instances if <code class="docutils literal notranslate"><span class="pre">affinity='precomputed'</span></code>, or distances between
instances if <code class="docutils literal notranslate"><span class="pre">affinity='precomputed_nearest_neighbors</span></code>. If a
sparse matrix is provided in a format other than <code class="docutils literal notranslate"><span class="pre">csr_matrix</span></code>,
<code class="docutils literal notranslate"><span class="pre">csc_matrix</span></code>, or <code class="docutils literal notranslate"><span class="pre">coo_matrix</span></code>, it will be converted into a
sparse <code class="docutils literal notranslate"><span class="pre">csr_matrix</span></code>.</p>
</dd>
<dt><strong>y</strong><span class="classifier">Ignored</span></dt><dd><p>Not used, present here for API consistency by convention.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><dl class="simple">
<dt><strong>self</strong><span class="classifier">object</span></dt><dd><p>A fitted instance of the estimator.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="sklearn.cluster.SpectralClustering.fit_predict">
<span class="sig-name descname"><span class="pre">fit_predict</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">y</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/3f89022fa/sklearn/cluster/_spectral.py#L756"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sklearn.cluster.SpectralClustering.fit_predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform spectral clustering on <code class="docutils literal notranslate"><span class="pre">X</span></code> and return cluster labels.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>X</strong><span class="classifier">{array-like, sparse matrix} of shape (n_samples, n_features) or (n_samples, n_samples)</span></dt><dd><p>Training instances to cluster, similarities / affinities between
instances if <code class="docutils literal notranslate"><span class="pre">affinity='precomputed'</span></code>, or distances between
instances if <code class="docutils literal notranslate"><span class="pre">affinity='precomputed_nearest_neighbors</span></code>. If a
sparse matrix is provided in a format other than <code class="docutils literal notranslate"><span class="pre">csr_matrix</span></code>,
<code class="docutils literal notranslate"><span class="pre">csc_matrix</span></code>, or <code class="docutils literal notranslate"><span class="pre">coo_matrix</span></code>, it will be converted into a
sparse <code class="docutils literal notranslate"><span class="pre">csr_matrix</span></code>.</p>
</dd>
<dt><strong>y</strong><span class="classifier">Ignored</span></dt><dd><p>Not used, present here for API consistency by convention.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><dl class="simple">
<dt><strong>labels</strong><span class="classifier">ndarray of shape (n_samples,)</span></dt><dd><p>Cluster labels.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="sklearn.cluster.SpectralClustering.get_metadata_routing">
<span class="sig-name descname"><span class="pre">get_metadata_routing</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/3f89022fa/sklearn/utils/_metadata_requests.py#L1243"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sklearn.cluster.SpectralClustering.get_metadata_routing" title="Permalink to this definition">¶</a></dt>
<dd><p>Get metadata routing of this object.</p>
<p>Please check <a class="reference internal" href="../../metadata_routing.html#metadata-routing"><span class="std std-ref">User Guide</span></a> on how the routing
mechanism works.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>routing</strong><span class="classifier">MetadataRequest</span></dt><dd><p>A <a class="reference internal" href="sklearn.utils.metadata_routing.MetadataRequest.html#sklearn.utils.metadata_routing.MetadataRequest" title="sklearn.utils.metadata_routing.MetadataRequest"><code class="xref py py-class docutils literal notranslate"><span class="pre">MetadataRequest</span></code></a> encapsulating
routing information.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="sklearn.cluster.SpectralClustering.get_params">
<span class="sig-name descname"><span class="pre">get_params</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">deep</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/3f89022fa/sklearn/base.py#L178"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sklearn.cluster.SpectralClustering.get_params" title="Permalink to this definition">¶</a></dt>
<dd><p>Get parameters for this estimator.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>deep</strong><span class="classifier">bool, default=True</span></dt><dd><p>If True, will return the parameters for this estimator and
contained subobjects that are estimators.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><dl class="simple">
<dt><strong>params</strong><span class="classifier">dict</span></dt><dd><p>Parameter names mapped to their values.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="sklearn.cluster.SpectralClustering.set_params">
<span class="sig-name descname"><span class="pre">set_params</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">params</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/3f89022fa/sklearn/base.py#L202"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sklearn.cluster.SpectralClustering.set_params" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the parameters of this estimator.</p>
<p>The method works on simple estimators as well as on nested objects
(such as <a class="reference internal" href="sklearn.pipeline.Pipeline.html#sklearn.pipeline.Pipeline" title="sklearn.pipeline.Pipeline"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pipeline</span></code></a>). The latter have
parameters of the form <code class="docutils literal notranslate"><span class="pre"><component>__<parameter></span></code> so that it’s
possible to update each component of a nested object.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>**params</strong><span class="classifier">dict</span></dt><dd><p>Estimator parameters.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><dl class="simple">
<dt><strong>self</strong><span class="classifier">estimator instance</span></dt><dd><p>Estimator instance.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>
</dd></dl>
<section id="examples-using-sklearn-cluster-spectralclustering">
<h2>Examples using <code class="docutils literal notranslate"><span class="pre">sklearn.cluster.SpectralClustering</span></code><a class="headerlink" href="#examples-using-sklearn-cluster-spectralclustering" title="Permalink to this heading">¶</a></h2>
<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="This example shows characteristics of different clustering algorithms on datasets that are "int..."><img alt="" src="../../_images/sphx_glr_plot_cluster_comparison_thumb.png" />
<p><a class="reference internal" href="../../auto_examples/cluster/plot_cluster_comparison.html#sphx-glr-auto-examples-cluster-plot-cluster-comparison-py"><span class="std std-ref">Comparing different clustering algorithms on toy datasets</span></a></p>
<div class="sphx-glr-thumbnail-title">Comparing different clustering algorithms on toy datasets</div>
</div></div><div class="clearer"></div></section>
</section>
</div>
<div class="container">
<footer class="sk-content-footer">
© 2007 - 2023, scikit-learn developers (BSD License).
<a href="../../_sources/modules/generated/sklearn.cluster.SpectralClustering.rst.txt" rel="nofollow">Show this page source</a>
</footer>
</div>
</div>
</div>
<script src="../../_static/js/vendor/bootstrap.min.js"></script>
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-22606712-2', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<script defer data-domain="scikit-learn.org" src="https://views.scientific-python.org/js/script.js">
</script>
<script src="../../_static/clipboard.min.js"></script>
<script src="../../_static/copybutton.js"></script>
<script>
$(document).ready(function() {
/* Add a [>>>] button on the top-right corner of code samples to hide
* the >>> and ... prompts and the output and thus make the code
* copyable. */
var div = $('.highlight-python .highlight,' +
'.highlight-python3 .highlight,' +
'.highlight-pycon .highlight,' +
'.highlight-default .highlight')
var pre = div.find('pre');
// get the styles from the current theme
pre.parent().parent().css('position', 'relative');
// create and add the button to all the code blocks that contain >>>
div.each(function(index) {
var jthis = $(this);
// tracebacks (.gt) contain bare text elements that need to be
// wrapped in a span to work with .nextUntil() (see later)
jthis.find('pre:has(.gt)').contents().filter(function() {
return ((this.nodeType == 3) && (this.data.trim().length > 0));
}).wrap('<span>');
});
/*** Add permalink buttons next to glossary terms ***/
$('dl.glossary > dt[id]').append(function() {
return ('<a class="headerlink" href="#' +
this.getAttribute('id') +
'" title="Permalink to this term">¶</a>');
});
});
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<script src="https://scikit-learn.org/versionwarning.js"></script>
</body>
</html>