Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Setting Parameters: Affinity | Spectral Clustering
Cluster Analysis in Python
course content

Conteúdo do Curso

Cluster Analysis in Python

Cluster Analysis in Python

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

book
Setting Parameters: Affinity

Well, that was not the result we were looking for. Can we improve it? Can we make the clustering algorithm learn to differ such structures?

The answer is yes - we need to set some parameters within the SpectralClustering function. The parameter we should change is affinity. This parameter defines how should affinity matrix be built (the math explanation of this is outside the scope of this course). By default, the parameter's value is 'rbf'. If we want to differ the clusters with such a structure as in the previous chapter, we should consider the 'nearest_neighbors' value of the parameter.

Tarefa

Swipe to start coding

  1. Import SpectralClustering function from sklearn.cluster.
  2. Create a SpectralClustering model object with 4 clusters and set the affinity parameter to 'nearest_neighbors'.
  3. Fit the data to the model and predict the labels. Save predicted labels as the 'prediction' column of data.
  4. Build the seaborn scatter plot with 'x' column of data on the x-axis, 'y' column of data on the y-axis for each value of 'prediction'. Then, display the plot.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 3
toggle bottom row

book
Setting Parameters: Affinity

Well, that was not the result we were looking for. Can we improve it? Can we make the clustering algorithm learn to differ such structures?

The answer is yes - we need to set some parameters within the SpectralClustering function. The parameter we should change is affinity. This parameter defines how should affinity matrix be built (the math explanation of this is outside the scope of this course). By default, the parameter's value is 'rbf'. If we want to differ the clusters with such a structure as in the previous chapter, we should consider the 'nearest_neighbors' value of the parameter.

Tarefa

Swipe to start coding

  1. Import SpectralClustering function from sklearn.cluster.
  2. Create a SpectralClustering model object with 4 clusters and set the affinity parameter to 'nearest_neighbors'.
  3. Fit the data to the model and predict the labels. Save predicted labels as the 'prediction' column of data.
  4. Build the seaborn scatter plot with 'x' column of data on the x-axis, 'y' column of data on the y-axis for each value of 'prediction'. Then, display the plot.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 3
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt