Git Product home page Git Product logo

actuallyroy / k-mean Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 17 KB

This repository contains an implementation of the K-Means clustering algorithm in Python, which is a popular unsupervised machine learning technique used for partitioning data into groups or clusters. This implementation provides a class, K_mean, that allows you to perform K-Means clustering on a given dataset.

Python 100.00%
kmeans-clustering machine-learning python

k-mean's Introduction

K-Means Clustering Algorithm

This repository contains an implementation of the K-Means clustering algorithm in Python, which is a popular unsupervised machine learning technique used for partitioning data into groups or clusters. This implementation provides a class, K_mean, that allows you to perform K-Means clustering on a given dataset.

Usage

To use this K-Means clustering implementation, follow these steps:

  1. Clone the Repository:

    git clone https://github.com/actuallyroy/K-Mean.git
    cd K-Mean
  2. Import the K_mean Class:

    Import the K_mean class in your Python script:

    from K_Mean import K_mean
  3. Prepare Your Data:

    Create or load your dataset and make sure it is in the appropriate format. You can use the provided example data or prepare your own data.

    Example data format:

    x = [14, 48, 83, ...]  # List of data points for the first dimension
    y = [64, 59, 10, ...]  # List of data points for the second dimension
    z = [62, 13, 2, ...]   # List of data points for the third dimension
    data = list(zip(x, y, z, x))  # Combine the dimensions into a list of tuples
  4. Create a K-Mean Object:

    Create a K_mean object by providing your data and the number of clusters (k) you want to create. Optionally, you can provide initial centroids:

    obj = K_mean(data, k=4, centroids=[])  # Initialize with your data, k value, and optional initial centroids
  5. Perform Clustering:

    You can perform clustering by calling the getClusters method:

    obj.getClusters()  # Perform K-Means clustering
  6. Visualize the Clusters:

    You can visualize the clustered data using the plot method, which provides a 2D or 3D scatter plot of the clusters:

    obj.plot()  # Visualize the clustered data
  7. Customization and Analysis:

    Feel free to customize the K-Means implementation or analyze the results, such as calculating cluster centroids, cluster inertia, or other metrics.

Example

An example of using the K-Means clustering implementation is provided in the script example.py. You can run this script to see how the K-Means algorithm works with sample data.

Dependencies

This implementation relies on the following Python libraries:

  • random: For generating random numbers.
  • matplotlib: For data visualization.
  • math: For mathematical calculations.

Author

k-mean's People

Contributors

actuallyroy avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.