Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sungwoncho/k_means_ruby
K-means Algorithm in Ruby
https://github.com/sungwoncho/k_means_ruby
Last synced: 3 months ago
JSON representation
K-means Algorithm in Ruby
- Host: GitHub
- URL: https://github.com/sungwoncho/k_means_ruby
- Owner: sungwoncho
- License: mit
- Created: 2015-03-13T11:37:37.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-14T02:37:57.000Z (almost 10 years ago)
- Last Synced: 2024-10-09T09:44:02.407Z (3 months ago)
- Language: Ruby
- Size: 148 KB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# k_means_ruby
[![Build Status](https://travis-ci.org/sungwoncho/k_means_ruby.svg?branch=master)](https://travis-ci.org/sungwoncho/k_means_ruby)
[![Coverage Status](https://coveralls.io/repos/sungwoncho/k_means_ruby/badge.svg?branch=master)](https://coveralls.io/r/sungwoncho/k_means_ruby?branch=master)An implementation of k-means algorithm in Ruby.
## Definition
K-means algorithm is a clustering algorithm for a Euclidean space. It assumes that there are k clusters in the beginning.
* Choose k points that are likely to be in different clusters.
* Make those the points centroids of clusters.
* For the remaining points:
* Find the centroid to which the point is closest.
* Merge the point into that cluster.
* Recalculate the centroid of that cluster.## Use
In your ruby console, require the main file:
`require './lib/k_means_ruby.rb'`
Define `Points` and `Clusters`:
```
p1 = KMeansRuby::Point.new(1,2)
p2 = KMeansRuby::Point.new(10,19)
...
c1 = KMeansRuby::Cluster.new(p1)
...
```Instantiate the `Algorithm`:
`algorithm = KMeansRuby::Algorithm.new(points=[p1, p2], clusters=[c1])`
Run the algorithm by calling `algorithm.run_once` or `algorithm.repeat_for(n)`
## Contributing
### TODO:
* Allow users to run the algorithm until the clusters do not change anymore.