Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
What is a K-Medoids Algorithm? | K-Medoids Algorithm
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

What is a K-Medoids Algorithm?

You did well in the first section! Now it's time to learn a new algorithm!

So, unlike centroid, medoid has to be a data point - which is the key difference. In the case of large and 'grouped' data there most likely will be an insignificant difference.

The K-Medoids algorithm works similarly to the K-Means, but in the first step, the random points have to be data points. These are medoids. Then, each data point is associated with the closest medoid by some metric. Then, the medoids swap with some data points, and the cost function (sum of the variances for all the points within a cluster) compares with the one in the previous step until we get the minimum possible values.

How to implement the K-Medoids algorithm using Python? The same way you did with the K-Means algorithm! The key function there is KMedoids from the sklearn_extra.cluster library. The algorithm is the next:

  1. Create a KMedoids model assigned to a certain variable.
  2. Compute K-Medoids clustering using the .fit() method of KMedoids object with data set as a parameter.
  3. Predict the labels using the fitted model by applying the .predict() function to the KMedoids object with the data set as a parameter.
  4. (not necessary) Visualize the result of clustering.

For example, let's try to cluster the points using the K-Medoids method. The scatter plot for the data points is below.

Tarefa

Implement the K-Medoids algorithm to divide the points into two groups. To do it, follow the next steps:

  1. Import KMedoids from sklearn_extra.cluster.
  2. Create a KMedoids model object with 2 clusters assigned to the model variable.
  3. Fit the data to the model.
  4. Predict the labels for data using model. Save the labels within the prediction variable.
  5. Add 'prediction' column to data filled with prediction values.
  6. Build a scatter plot with 'x' column on the x-axis, 'y' column on the y-axis, and a 'prediction' column as the color of the point. Do not forget to apply the respective function of plt to display the plot.

Tarefa

Implement the K-Medoids algorithm to divide the points into two groups. To do it, follow the next steps:

  1. Import KMedoids from sklearn_extra.cluster.
  2. Create a KMedoids model object with 2 clusters assigned to the model variable.
  3. Fit the data to the model.
  4. Predict the labels for data using model. Save the labels within the prediction variable.
  5. Add 'prediction' column to data filled with prediction values.
  6. Build a scatter plot with 'x' column on the x-axis, 'y' column on the y-axis, and a 'prediction' column as the color of the point. Do not forget to apply the respective function of plt to display the plot.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 2. Capítulo 1
toggle bottom row

What is a K-Medoids Algorithm?

You did well in the first section! Now it's time to learn a new algorithm!

So, unlike centroid, medoid has to be a data point - which is the key difference. In the case of large and 'grouped' data there most likely will be an insignificant difference.

The K-Medoids algorithm works similarly to the K-Means, but in the first step, the random points have to be data points. These are medoids. Then, each data point is associated with the closest medoid by some metric. Then, the medoids swap with some data points, and the cost function (sum of the variances for all the points within a cluster) compares with the one in the previous step until we get the minimum possible values.

How to implement the K-Medoids algorithm using Python? The same way you did with the K-Means algorithm! The key function there is KMedoids from the sklearn_extra.cluster library. The algorithm is the next:

  1. Create a KMedoids model assigned to a certain variable.
  2. Compute K-Medoids clustering using the .fit() method of KMedoids object with data set as a parameter.
  3. Predict the labels using the fitted model by applying the .predict() function to the KMedoids object with the data set as a parameter.
  4. (not necessary) Visualize the result of clustering.

For example, let's try to cluster the points using the K-Medoids method. The scatter plot for the data points is below.

Tarefa

Implement the K-Medoids algorithm to divide the points into two groups. To do it, follow the next steps:

  1. Import KMedoids from sklearn_extra.cluster.
  2. Create a KMedoids model object with 2 clusters assigned to the model variable.
  3. Fit the data to the model.
  4. Predict the labels for data using model. Save the labels within the prediction variable.
  5. Add 'prediction' column to data filled with prediction values.
  6. Build a scatter plot with 'x' column on the x-axis, 'y' column on the y-axis, and a 'prediction' column as the color of the point. Do not forget to apply the respective function of plt to display the plot.

Tarefa

Implement the K-Medoids algorithm to divide the points into two groups. To do it, follow the next steps:

  1. Import KMedoids from sklearn_extra.cluster.
  2. Create a KMedoids model object with 2 clusters assigned to the model variable.
  3. Fit the data to the model.
  4. Predict the labels for data using model. Save the labels within the prediction variable.
  5. Add 'prediction' column to data filled with prediction values.
  6. Build a scatter plot with 'x' column on the x-axis, 'y' column on the y-axis, and a 'prediction' column as the color of the point. Do not forget to apply the respective function of plt to display the plot.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 2. Capítulo 1
toggle bottom row

What is a K-Medoids Algorithm?

You did well in the first section! Now it's time to learn a new algorithm!

So, unlike centroid, medoid has to be a data point - which is the key difference. In the case of large and 'grouped' data there most likely will be an insignificant difference.

The K-Medoids algorithm works similarly to the K-Means, but in the first step, the random points have to be data points. These are medoids. Then, each data point is associated with the closest medoid by some metric. Then, the medoids swap with some data points, and the cost function (sum of the variances for all the points within a cluster) compares with the one in the previous step until we get the minimum possible values.

How to implement the K-Medoids algorithm using Python? The same way you did with the K-Means algorithm! The key function there is KMedoids from the sklearn_extra.cluster library. The algorithm is the next:

  1. Create a KMedoids model assigned to a certain variable.
  2. Compute K-Medoids clustering using the .fit() method of KMedoids object with data set as a parameter.
  3. Predict the labels using the fitted model by applying the .predict() function to the KMedoids object with the data set as a parameter.
  4. (not necessary) Visualize the result of clustering.

For example, let's try to cluster the points using the K-Medoids method. The scatter plot for the data points is below.

Tarefa

Implement the K-Medoids algorithm to divide the points into two groups. To do it, follow the next steps:

  1. Import KMedoids from sklearn_extra.cluster.
  2. Create a KMedoids model object with 2 clusters assigned to the model variable.
  3. Fit the data to the model.
  4. Predict the labels for data using model. Save the labels within the prediction variable.
  5. Add 'prediction' column to data filled with prediction values.
  6. Build a scatter plot with 'x' column on the x-axis, 'y' column on the y-axis, and a 'prediction' column as the color of the point. Do not forget to apply the respective function of plt to display the plot.

Tarefa

Implement the K-Medoids algorithm to divide the points into two groups. To do it, follow the next steps:

  1. Import KMedoids from sklearn_extra.cluster.
  2. Create a KMedoids model object with 2 clusters assigned to the model variable.
  3. Fit the data to the model.
  4. Predict the labels for data using model. Save the labels within the prediction variable.
  5. Add 'prediction' column to data filled with prediction values.
  6. Build a scatter plot with 'x' column on the x-axis, 'y' column on the y-axis, and a 'prediction' column as the color of the point. Do not forget to apply the respective function of plt to display the plot.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

You did well in the first section! Now it's time to learn a new algorithm!

So, unlike centroid, medoid has to be a data point - which is the key difference. In the case of large and 'grouped' data there most likely will be an insignificant difference.

The K-Medoids algorithm works similarly to the K-Means, but in the first step, the random points have to be data points. These are medoids. Then, each data point is associated with the closest medoid by some metric. Then, the medoids swap with some data points, and the cost function (sum of the variances for all the points within a cluster) compares with the one in the previous step until we get the minimum possible values.

How to implement the K-Medoids algorithm using Python? The same way you did with the K-Means algorithm! The key function there is KMedoids from the sklearn_extra.cluster library. The algorithm is the next:

  1. Create a KMedoids model assigned to a certain variable.
  2. Compute K-Medoids clustering using the .fit() method of KMedoids object with data set as a parameter.
  3. Predict the labels using the fitted model by applying the .predict() function to the KMedoids object with the data set as a parameter.
  4. (not necessary) Visualize the result of clustering.

For example, let's try to cluster the points using the K-Medoids method. The scatter plot for the data points is below.

Tarefa

Implement the K-Medoids algorithm to divide the points into two groups. To do it, follow the next steps:

  1. Import KMedoids from sklearn_extra.cluster.
  2. Create a KMedoids model object with 2 clusters assigned to the model variable.
  3. Fit the data to the model.
  4. Predict the labels for data using model. Save the labels within the prediction variable.
  5. Add 'prediction' column to data filled with prediction values.
  6. Build a scatter plot with 'x' column on the x-axis, 'y' column on the y-axis, and a 'prediction' column as the color of the point. Do not forget to apply the respective function of plt to display the plot.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 2. Capítulo 1
Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt