Course Content
Cluster Analysis in Python
Cluster Analysis in Python
Cluster Centers
In the previous chapter, we compared the K-Means and K-Medoids algorithms. It was mentioned that, unlike K-Means, the K-Medoids algorithm has data points as medoids. Let's visualize the differences.
For example, for the training dataset with three clusters we can visualize the clusters and their centers for both K-Means and K-Medoids. The results are displayed below.
If you watch closely to the right chart and compare it with the central one, you will notice that marked points are data points, unlike the points on the left chart. I've marked these points with green arrows. Let's represent the difference using a more obvious example! The result of clustering using the K-Means algorithm, and cluster centers (labeled with 10) are displayed below.
Task
For the same dataset of points data
compute the K-Medoids algorithm,
and display the cluster centers. Follow the next steps:
- Import
KMedoids
function fromsklearn_extra.cluster
library. - Create
KMedoids
modelmodel
with 2 clusters. - Fit the
data
to themodel
. - Add
'prediction'
column with predicted bymodel
labels todata
. - Use the
.cluster_centers_
method to extract the clusters centers array. - Visualize the clusters (already done) and centers. Within the second
.scatterplot
function sethue
to10
, ands
to150
.
Thanks for your feedback!
Cluster Centers
In the previous chapter, we compared the K-Means and K-Medoids algorithms. It was mentioned that, unlike K-Means, the K-Medoids algorithm has data points as medoids. Let's visualize the differences.
For example, for the training dataset with three clusters we can visualize the clusters and their centers for both K-Means and K-Medoids. The results are displayed below.
If you watch closely to the right chart and compare it with the central one, you will notice that marked points are data points, unlike the points on the left chart. I've marked these points with green arrows. Let's represent the difference using a more obvious example! The result of clustering using the K-Means algorithm, and cluster centers (labeled with 10) are displayed below.
Task
For the same dataset of points data
compute the K-Medoids algorithm,
and display the cluster centers. Follow the next steps:
- Import
KMedoids
function fromsklearn_extra.cluster
library. - Create
KMedoids
modelmodel
with 2 clusters. - Fit the
data
to themodel
. - Add
'prediction'
column with predicted bymodel
labels todata
. - Use the
.cluster_centers_
method to extract the clusters centers array. - Visualize the clusters (already done) and centers. Within the second
.scatterplot
function sethue
to10
, ands
to150
.
Thanks for your feedback!
Cluster Centers
In the previous chapter, we compared the K-Means and K-Medoids algorithms. It was mentioned that, unlike K-Means, the K-Medoids algorithm has data points as medoids. Let's visualize the differences.
For example, for the training dataset with three clusters we can visualize the clusters and their centers for both K-Means and K-Medoids. The results are displayed below.
If you watch closely to the right chart and compare it with the central one, you will notice that marked points are data points, unlike the points on the left chart. I've marked these points with green arrows. Let's represent the difference using a more obvious example! The result of clustering using the K-Means algorithm, and cluster centers (labeled with 10) are displayed below.
Task
For the same dataset of points data
compute the K-Medoids algorithm,
and display the cluster centers. Follow the next steps:
- Import
KMedoids
function fromsklearn_extra.cluster
library. - Create
KMedoids
modelmodel
with 2 clusters. - Fit the
data
to themodel
. - Add
'prediction'
column with predicted bymodel
labels todata
. - Use the
.cluster_centers_
method to extract the clusters centers array. - Visualize the clusters (already done) and centers. Within the second
.scatterplot
function sethue
to10
, ands
to150
.
Thanks for your feedback!
In the previous chapter, we compared the K-Means and K-Medoids algorithms. It was mentioned that, unlike K-Means, the K-Medoids algorithm has data points as medoids. Let's visualize the differences.
For example, for the training dataset with three clusters we can visualize the clusters and their centers for both K-Means and K-Medoids. The results are displayed below.
If you watch closely to the right chart and compare it with the central one, you will notice that marked points are data points, unlike the points on the left chart. I've marked these points with green arrows. Let's represent the difference using a more obvious example! The result of clustering using the K-Means algorithm, and cluster centers (labeled with 10) are displayed below.
Task
For the same dataset of points data
compute the K-Medoids algorithm,
and display the cluster centers. Follow the next steps:
- Import
KMedoids
function fromsklearn_extra.cluster
library. - Create
KMedoids
modelmodel
with 2 clusters. - Fit the
data
to themodel
. - Add
'prediction'
column with predicted bymodel
labels todata
. - Use the
.cluster_centers_
method to extract the clusters centers array. - Visualize the clusters (already done) and centers. Within the second
.scatterplot
function sethue
to10
, ands
to150
.