k_means_pp 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +18 -0
- data/README.md +2 -0
- data/examples/example_block.rb +0 -1
- data/examples/example_csv.rb +0 -1
- data/examples/example_debug.rb +0 -1
- data/examples/example_huge.rb +0 -1
- data/examples/example_simple.rb +0 -1
- data/k_means_pp.gemspec +3 -3
- data/lib/k_means_pp.rb +4 -1
- data/lib/k_means_pp/version.rb +1 -1
- data/spec/lib/k_means_pp_spec.rb +15 -2
- metadata +3 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c559a4b71f8e96d813e46b25c718956c209561e3
|
4
|
+
data.tar.gz: fbf9650f96cffa2108bc10dbd687bd80318d992a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33c2ec2d2ace4de6cad7752185fa0f5014a47c1e02b1f56571c75f03d8aa1b32940565ae2d2f10525879a50648f32b29331a8b81d1975567c975533ff44284d1
|
7
|
+
data.tar.gz: 6e7cb457d33d97f3f7e331978e57781193a039b750c7e683908a536b9fe76670d048f84d6d0191f8a3de24d58d46aad05532d0babbdd3d32d91e5377fe151780
|
data/.rspec
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
data/examples/example_block.rb
CHANGED
data/examples/example_csv.rb
CHANGED
data/examples/example_debug.rb
CHANGED
data/examples/example_huge.rb
CHANGED
data/examples/example_simple.rb
CHANGED
data/k_means_pp.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'rake', '~> 10.3'
|
33
33
|
spec.add_development_dependency 'rubocop', '~> 0.26'
|
34
34
|
spec.add_development_dependency 'pry', '~> 0.10'
|
35
|
-
spec.add_development_dependency 'pry-byebug', '~> 2.0'
|
36
|
-
spec.add_development_dependency 'ruby-prof', '~> 0.15'
|
37
|
-
spec.add_development_dependency 'gnuplot', '~> 2.6'
|
35
|
+
# spec.add_development_dependency 'pry-byebug', '~> 2.0'
|
36
|
+
# spec.add_development_dependency 'ruby-prof', '~> 0.15'
|
37
|
+
# spec.add_development_dependency 'gnuplot', '~> 2.6'
|
38
38
|
end
|
data/lib/k_means_pp.rb
CHANGED
@@ -34,7 +34,7 @@ class KMeansPP
|
|
34
34
|
instance = new(points, clusters_count, &block)
|
35
35
|
instance.group_points
|
36
36
|
instance.centroids.map do |centroid|
|
37
|
-
cluster_for_centroid(centroid, points, &block)
|
37
|
+
cluster_for_centroid(centroid, instance.points, &block)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -113,6 +113,9 @@ class KMeansPP
|
|
113
113
|
# @param clusters_count [Fixnum] Number of clusters ("k").
|
114
114
|
# @yieldreturn [Array<Numeric>]
|
115
115
|
def initialize(points, clusters_count)
|
116
|
+
# Do not mutate original structure
|
117
|
+
points = points.dup
|
118
|
+
|
116
119
|
if block_given?
|
117
120
|
points.map! do |point_obj|
|
118
121
|
point_ary = yield(point_obj)
|
data/lib/k_means_pp/version.rb
CHANGED
data/spec/lib/k_means_pp_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'spec_helper'
|
2
1
|
require 'csv'
|
3
2
|
|
4
3
|
RSpec.describe 'Superman' do
|
5
4
|
it 'does it again' do
|
6
|
-
|
5
|
+
raw_data = File.read('./spec/resources/points.csv')
|
6
|
+
data = CSV.parse(raw_data).map do |row|
|
7
7
|
[row[0].to_f, row[1].to_f]
|
8
8
|
end
|
9
9
|
|
@@ -59,4 +59,17 @@ RSpec.describe 'Superman' do
|
|
59
59
|
expect(clusters.size).to eq(3)
|
60
60
|
expect(clusters.first.points.first).to be_a(Hash)
|
61
61
|
end
|
62
|
+
|
63
|
+
it 'does not mutate original structure' do
|
64
|
+
data = [
|
65
|
+
[0.3968, 1.9431],
|
66
|
+
[9.3348, 6.7843]
|
67
|
+
]
|
68
|
+
|
69
|
+
backup = data.dup
|
70
|
+
clusters = KMeansPP.clusters(data, 2)
|
71
|
+
|
72
|
+
expect(data).to eq(backup)
|
73
|
+
expect(clusters.size).to eq(2)
|
74
|
+
end
|
62
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k_means_pp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oldrich Vetesnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,48 +108,6 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.10'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: pry-byebug
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '2.0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '2.0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: ruby-prof
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0.15'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0.15'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: gnuplot
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - "~>"
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '2.6'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - "~>"
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '2.6'
|
153
111
|
description: 'This is a Ruby implementation of the k-means++ algorithm for data clustering.
|
154
112
|
In other words: Grouping a bunch of X, Y points into K groups.'
|
155
113
|
email:
|
@@ -160,6 +118,7 @@ extra_rdoc_files: []
|
|
160
118
|
files:
|
161
119
|
- ".gitignore"
|
162
120
|
- ".rspec"
|
121
|
+
- ".travis.yml"
|
163
122
|
- ".yardopts"
|
164
123
|
- Gemfile
|
165
124
|
- LICENSE.txt
|