{"id":25600950,"url":"https://github.com/coby-sonn/kmeans-python-c","last_synced_at":"2026-05-14T21:02:26.836Z","repository":{"id":278159992,"uuid":"934712705","full_name":"Coby-Sonn/KMeans-Python-C","owner":"Coby-Sonn","description":"An efficient K-Means clustering implementation combining Python for preprocessing and a C extension for optimized computations, featuring K-Means++ initialization and linked-list memory management.","archived":false,"fork":false,"pushed_at":"2025-02-18T09:41:15.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-30T14:27:50.216Z","etag":null,"topics":["kmeans","machine-learning","memory-management","python-c-extension"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Coby-Sonn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-18T09:35:20.000Z","updated_at":"2025-02-18T09:41:19.000Z","dependencies_parsed_at":"2025-02-18T10:47:41.020Z","dependency_job_id":null,"html_url":"https://github.com/Coby-Sonn/KMeans-Python-C","commit_stats":null,"previous_names":["coby-sonn/kmeans-python-c"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Coby-Sonn/KMeans-Python-C","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coby-Sonn%2FKMeans-Python-C","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coby-Sonn%2FKMeans-Python-C/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coby-Sonn%2FKMeans-Python-C/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coby-Sonn%2FKMeans-Python-C/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Coby-Sonn","download_url":"https://codeload.github.com/Coby-Sonn/KMeans-Python-C/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coby-Sonn%2FKMeans-Python-C/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33043249,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kmeans","machine-learning","memory-management","python-c-extension"],"created_at":"2025-02-21T15:37:39.887Z","updated_at":"2026-05-14T21:02:26.801Z","avatar_url":"https://github.com/Coby-Sonn.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# K-Means Clustering Implementation in Python and C\n\nThis repository contains an implementation of the K-Means clustering algorithm, leveraging both Python and C for optimized performance. This was built during university studies in a C \u0026 Python data analysis course. \n\n## Overview\n- **Python Implementation**: Handles data processing and initialization using K-Means++.\n- **C Extension**: Optimized clustering computation using linked lists for efficient memory management.\n\n## Files\n- `kmeans_pp.py` - Python implementation, including K-Means++ initialization.\n- `kmeansmodule.c` - C extension implementing the core clustering logic.\n- `setup.py` - Build script for compiling the C extension into a Python module.\n\n## Installation\n### Prerequisites\n- Python 3.x installed.\n- A C compiler such as `gcc`.\n\n### Building the C Extension\nRun the following command to compile the C module:\n```sh\npython setup.py build_ext --inplace\n```\nThis will generate a shared library (`mykmeanssp.*.so` or `.pyd` on Windows) that can be imported into Python.\n\n## How to Run\n### Running the Python Implementation\n#### Command Syntax:\n```sh\npython kmeans_pp.py \u003ck\u003e [\u003cmax_iter\u003e] \u003cepsilon\u003e \u003cinput_file_1\u003e \u003cinput_file_2\u003e\n```\n- `\u003ck\u003e`: Number of clusters (integer \u003e 1 and \u003c N, where N is the number of points).\n- `\u003cmax_iter\u003e`: (Optional) Maximum number of iterations (default: 300, max: 1000).\n- `\u003cepsilon\u003e`: Convergence threshold (float \u003e= 0).\n- `\u003cinput_file_1\u003e`, `\u003cinput_file_2\u003e`: CSV files containing the input data.\n\n#### Example:\n```sh\npython kmeans_pp.py 3 300 0.001 data1.csv data2.csv\n```\n\n## Output Format\n- The program prints the initial centroids' indices.\n- The final cluster centroids are printed, with each centroid on a new line formatted to 4 decimal places.\n\n## Notes\n- Input files must be in CSV format with numerical values.\n- The implementation uses the K-Means++ initialization method for better convergence.\n- The Python script interfaces with the optimized C extension for better performance.\n\n## License\nThis project is released under the MIT License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoby-sonn%2Fkmeans-python-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoby-sonn%2Fkmeans-python-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoby-sonn%2Fkmeans-python-c/lists"}