K-Medoids Clustering Implementation
├── Introduction
│ └── Overview of K-Medoids
├── Setting Up the Environment
│ ├── Importing Libraries
│ └── Generating the Dataset
├── Implementing K-Medoids
│ ├── Data Preparation
│ ├── Model Training
│ └── Identifying Medoids
├── Visualization
│ └── K-Medoids Clustering Visualization
└── Conclusion
└── Insights and Observations
1. Introduction
Overview of K-Medoids
- K-Medoids is a clustering algorithm similar to K-Means, but instead of calculating the mean of the objects in a cluster, it selects actual objects as the representative points (medoids).
2. Setting Up the Environment
Importing Libraries
# Python code to import necessary libraries
import numpy as np
import matplotlib.pyplot as plt
from pyclustering.cluster.kmedoids import kmedoids
from pyclustering.cluster import cluster_visualizer
from pyclustering.utils import read_sample
from pyclustering.samples.definitions import SIMPLE_SAMPLES
Generating the Dataset
# Python code to generate a sample dataset
X = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
3. Implementing K-Medoids
Data Preparation
- Choosing initial medoids.
initial_medoids = [1, 10]
Model Training
# Python code to train the K-Medoids model
kmedoids_instance = kmedoids(X, initial_medoids)
kmedoids_instance.process()
Identifying Medoids
# Python code to identify the medoids
medoids = kmedoids_instance.get_medoids()
4. Visualization