Spectral clustering (spectral clustering) Python visualization implementation __python

Source: Internet
Author: User
Spectral Clustering Introduction:

This blog for the introduction of spectral clustering, including formula derivation is quite in place, then the class ppt is cut this figure, so can understand the words pretty good. http://www.cnblogs.com/FengYan/archive/2012/06/21/2553999.html Algorithm python implementation:

For the derivation of the formula what the individual understanding is not very deep, the following directly say the implementation of the algorithm bar:

First, because this algorithm is actually called the spectral method, for community mining or map mining, so to use in the cluster, you need a thing to directly connect to the sample, to achieve a similar diagram of the structure, here using KNN, is the former K neighbors have connectivity, others do not. So we can get the matrix W, however, there is a small problem, point a K nearest neighbor has B, but B's K nearest neighbor may be without a, this time, in order to let the Matrix W is a symmetric matrix, we adopt one or the principle, will w= (W+WT)/2 w= (w+w^t)/2, This will get a symmetric similarity matrix.

The second step is very simple, calculate the degree of each node, get the Matrix D.

To get the Laplace matrix L=d−w l=d-w, very simple, do not paste code.

Obtains the characteristic matrix of the Laplace Matrix L, which is good with the built-in function.

After obtaining the feature matrix, we use the Kmeans method to cluster the feature matrix, each feature vector is a column of the feature matrix, and each row is a cluster sample. Such a cluster is the ultimate achievement. For the sake of illustration, I use the Kmeans function in Sklearn directly here to invoke:

OK, here is basically done, the classification has been basically completed, and finally a wave of visualization, to see our experimental results, because the spectral cluster can be clustered on the spherical data, so we directly to try the spherical dataset:

Nice, it looks good.
All right, here's the experiment.
Full code Address: github/pp8818 Remember to star Oh ~ ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.