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.
Swipe to start coding
- Import
SpectralClusteringfunction fromsklearn.cluster. - Create a
SpectralClusteringmodel object with 4 clusters and set theaffinityparameter to'nearest_neighbors'. - Fit the
datato themodeland predict the labels. Save predicted labels as the'prediction'column ofdata. - Build the
seabornscatter plot with'x'column ofdataon the x-axis,'y'column ofdataon the y-axis for each value of'prediction'. Then, display the plot.
Рішення
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Сумаризуйте цей розділ
Пояснити код у file
Пояснити, чому file не вирішує завдання
Awesome!
Completion rate improved to 3.57
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.
Swipe to start coding
- Import
SpectralClusteringfunction fromsklearn.cluster. - Create a
SpectralClusteringmodel object with 4 clusters and set theaffinityparameter to'nearest_neighbors'. - Fit the
datato themodeland predict the labels. Save predicted labels as the'prediction'column ofdata. - Build the
seabornscatter plot with'x'column ofdataon the x-axis,'y'column ofdataon the y-axis for each value of'prediction'. Then, display the plot.
Рішення
Дякуємо за ваш відгук!
single