Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer What is a Spectral Clustering? | Spectral Clustering
Cluster Analysis in Python
course content

Cursusinhoud

Cluster Analysis in Python

Cluster Analysis in Python

1. K-Means Algorithm
2. K-Medoids Algorithm
3. Hierarchical Clustering
4. Spectral Clustering

book
What is a Spectral Clustering?

Welcome to the fourth section of the course! In this section, we will learn the last (but not the last overall) clustering method.

This method is heavily based on math, such as eigenvalues, laplacians, graphs, and kernels. We will not dig into the algorithm itself but will consider the main cases of its usage.

You might forget all the charts you saw in the course, but in the second section, we considered an interesting set of points. Look at the scatterplot below.

And look below at the results of the K-Means algorithm.

Well, that's not what we were looking for. So, how can you implement the spectral clustering algorithm in Python? The key function is SpectralClustering from sklearn.cluster. The algorithm of prediction is the same as in the previous section:

  1. Create SpectralClustering model with k clusters using n_clusters = k parameter.
  2. Fit the numerical data and predict the labels using the .fit_predict() method of model and passing numerical data as a parameter.

Then, if needed, you can visualize the results.

Let's find out can the algorithm heavily based on strong math correctly define the clusters?

Taak

Swipe to start coding

  1. Import SpectralClustering function from sklearn.cluster.
  2. Create a SpectralClustering model with 2 clusters named model.
  3. Fit the data and predict the labels using model. Save predicted labels within the 'prediction' column of the data.
  4. Build a scatter plot (using seaborn) with 'x' column on the x-axis, 'y' column on the y-axis, and each point colored with respect to the 'prediction' column of the data.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 1
toggle bottom row

book
What is a Spectral Clustering?

Welcome to the fourth section of the course! In this section, we will learn the last (but not the last overall) clustering method.

This method is heavily based on math, such as eigenvalues, laplacians, graphs, and kernels. We will not dig into the algorithm itself but will consider the main cases of its usage.

You might forget all the charts you saw in the course, but in the second section, we considered an interesting set of points. Look at the scatterplot below.

And look below at the results of the K-Means algorithm.

Well, that's not what we were looking for. So, how can you implement the spectral clustering algorithm in Python? The key function is SpectralClustering from sklearn.cluster. The algorithm of prediction is the same as in the previous section:

  1. Create SpectralClustering model with k clusters using n_clusters = k parameter.
  2. Fit the numerical data and predict the labels using the .fit_predict() method of model and passing numerical data as a parameter.

Then, if needed, you can visualize the results.

Let's find out can the algorithm heavily based on strong math correctly define the clusters?

Taak

Swipe to start coding

  1. Import SpectralClustering function from sklearn.cluster.
  2. Create a SpectralClustering model with 2 clusters named model.
  3. Fit the data and predict the labels using model. Save predicted labels within the 'prediction' column of the data.
  4. Build a scatter plot (using seaborn) with 'x' column on the x-axis, 'y' column on the y-axis, and each point colored with respect to the 'prediction' column of the data.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 1
Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Onze excuses dat er iets mis is gegaan. Wat is er gebeurd?
some-alt