Course Content
Cluster Analysis in Python
Cluster Analysis in Python
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.
Task
- Import
SpectralClustering
function fromsklearn.cluster
. - Create a
SpectralClustering
model object with 4 clusters and set theaffinity
parameter to'nearest_neighbors'
. - Fit the
data
to themodel
and predict the labels. Save predicted labels as the'prediction'
column ofdata
. - Build the
seaborn
scatter plot with'x'
column ofdata
on the x-axis,'y'
column ofdata
on the y-axis for each value of'prediction'
. Then, display the plot.
Task
- Import
SpectralClustering
function fromsklearn.cluster
. - Create a
SpectralClustering
model object with 4 clusters and set theaffinity
parameter to'nearest_neighbors'
. - Fit the
data
to themodel
and predict the labels. Save predicted labels as the'prediction'
column ofdata
. - Build the
seaborn
scatter plot with'x'
column ofdata
on the x-axis,'y'
column ofdata
on the y-axis for each value of'prediction'
. Then, display the plot.
Everything was clear?
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.
Task
- Import
SpectralClustering
function fromsklearn.cluster
. - Create a
SpectralClustering
model object with 4 clusters and set theaffinity
parameter to'nearest_neighbors'
. - Fit the
data
to themodel
and predict the labels. Save predicted labels as the'prediction'
column ofdata
. - Build the
seaborn
scatter plot with'x'
column ofdata
on the x-axis,'y'
column ofdata
on the y-axis for each value of'prediction'
. Then, display the plot.
Task
- Import
SpectralClustering
function fromsklearn.cluster
. - Create a
SpectralClustering
model object with 4 clusters and set theaffinity
parameter to'nearest_neighbors'
. - Fit the
data
to themodel
and predict the labels. Save predicted labels as the'prediction'
column ofdata
. - Build the
seaborn
scatter plot with'x'
column ofdata
on the x-axis,'y'
column ofdata
on the y-axis for each value of'prediction'
. Then, display the plot.
Everything was clear?
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.
Task
- Import
SpectralClustering
function fromsklearn.cluster
. - Create a
SpectralClustering
model object with 4 clusters and set theaffinity
parameter to'nearest_neighbors'
. - Fit the
data
to themodel
and predict the labels. Save predicted labels as the'prediction'
column ofdata
. - Build the
seaborn
scatter plot with'x'
column ofdata
on the x-axis,'y'
column ofdata
on the y-axis for each value of'prediction'
. Then, display the plot.
Task
- Import
SpectralClustering
function fromsklearn.cluster
. - Create a
SpectralClustering
model object with 4 clusters and set theaffinity
parameter to'nearest_neighbors'
. - Fit the
data
to themodel
and predict the labels. Save predicted labels as the'prediction'
column ofdata
. - Build the
seaborn
scatter plot with'x'
column ofdata
on the x-axis,'y'
column ofdata
on the y-axis for each value of'prediction'
. Then, display the plot.
Everything was clear?
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.
Task
- Import
SpectralClustering
function fromsklearn.cluster
. - Create a
SpectralClustering
model object with 4 clusters and set theaffinity
parameter to'nearest_neighbors'
. - Fit the
data
to themodel
and predict the labels. Save predicted labels as the'prediction'
column ofdata
. - Build the
seaborn
scatter plot with'x'
column ofdata
on the x-axis,'y'
column ofdata
on the y-axis for each value of'prediction'
. Then, display the plot.