This project provides an implementation of the K-Means clustering algorithm using Python and the scikit-learn
library. K-Means is a popular unsupervised learning algorithm for clustering data into a predefined number of clusters. This example demonstrates the application of K-Means to a synthetic dataset and includes visualization of clustering results in 2D and 3D.
- Data Preparation: Creation of a synthetic dataset suitable for clustering analysis.
- K-Means Clustering: Application of the K-Means algorithm with customization options for the number of clusters and initialization methods.
- Visualization: 2D and 3D visualization of clustering results using PCA (Principal Component Analysis) for dimensionality reduction.
- Interactive Analysis: Code structured to easily modify parameters and visualize different outcomes.
To run this project, you will need the following libraries:
numpy
matplotlib
sklearn
You can install these with pip:
pip install numpy matplotlib scikit-learn
The project is structured into several Jupyter Notebook cells, which include:
- Data Setup: Configure the synthetic dataset.
- K-Means Implementation: Apply the K-Means algorithm to the dataset.
- 2D Visualization: Reduce dimensionality to two dimensions using PCA and visualize the results.
- 3D Visualization: Reduce dimensionality to three dimensions for a different perspective.
Open the Jupyter Notebook and execute the cells sequentially to observe how the K-Means algorithm clusters the dataset. Modify the n_clusters
parameter in the KMeans function call to experiment with different numbers of clusters.
After running the notebook, you will see scatter plots showing the data points colored according to the cluster they belong to, with cluster centers marked in red.
Contributions to this project are welcome! Please fork the repository and submit a pull request with your enhancements.
This project is open-sourced under the MIT license. See the LICENSE
file for more details.
For questions or feedback, please reach out to [[email protected]].
Enjoy clustering and visualizing your data!