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

Kursusindhold

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?

Opgave

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.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 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?

Opgave

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.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 1
Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Vi beklager, at noget gik galt. Hvad skete der?
some-alt