• This repository has been archived on 26/Feb/2019
  • Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

K Means

KMeans¶ ↑

Attempting to build a fast, memory efficient K-Means program.

Install¶ ↑

gem sources -a http://rubygems.org
sudo gem install k_means

How To Use¶ ↑

require 'rubygems'
require 'k_means'

data = [[1,1], [1,2], [1,1], [1000, 1000], [500, 500]]
kmeans = KMeans.new(data, :centroids => 2)
kmeans.inspect  # Use kmeans.view to get hold of the un-inspected array
=> [[3, 4], [0, 1, 2]]

Custom Centroids¶ ↑

require 'rubygems'
require 'k_means'

# Your custom centroid needs to have #position and #reposition methods
class CustomCentroid
  attr_accessor :position
  def initialize(position); @position = position; end
  def reposition(nodes, centroid_positions); end
end

custom_centroids = []
2.times { custom_centroids << CustomCentroid.new([1,1]) }

data = [[1,1], [1,2], [1,1], [1000, 1000], [500, 500]]
kmeans = KMeans.new(data, :custom_centroids => custom_centroids)

Distance Measurements¶ ↑

KMeans uses the Distance Measures Gem (github.com/reddavis/Distance-Measures) so we get quite a range of distance measurements.

The measurements currently available are:

euclidean_distance

cosine_similarity

jaccard_index

jaccard_distance

binary_jaccard_index

binary_jaccard_distance

tanimoto_coefficient

To specify a particular one to use in the KMeans algorithm, just provide it as an option:

KMeans.new(@data, :distance_measure => :jaccard_index)
KMeans.new(@data, :distance_measure => :cosine_similarity)
KMeans.new(@data, :distance_measure => :tanimoto_coefficient)

You get the idea…

Benchmarks¶ ↑

# 1000 records with 50 dimensions
data = Array.new(1000) {Array.new(50) {rand(10)}}
ai4r_data = Ai4r::Data::DataSet.new(:data_items=> data)

# Clustering can happen in magical ways
# so lets do it over multiple times
n = 5

Benchmark.bm do |x|
  x.report('KMeans') do
    n.times { KMeans.new(data) }
  end
  x.report("Ai4R") do
    n.times do
      b = Ai4r::Clusterers::KMeans.new
      b.build(ai4r_data, 4)
    end
  end
end
         user     system      total        real
KMeans 15.960000   0.030000  15.990000 ( 16.062639)
Ai4R   70.230000   0.180000  70.410000 ( 70.704843)

Thanks¶ ↑

Copyright © 2009 Red Davis. See LICENSE for details.

More Repositories

1

RDActionSheet

Class to make a easily customisable Action Sheet for iOS
Objective-C
186
star
2

Asynchrone

Extensions and additions to AsyncSequence, AsyncStream and AsyncThrowingStream.
Swift
137
star
3

freelancer-tools

List of useful tools for freelancers
81
star
4

REDActionSheet

Tweetbot action sheet
Objective-C
51
star
5

Naive-Bayes

Simple Naive Bayes classifier
Ruby
47
star
6

Crypto-Icons-API

API for crypto icons
HTML
41
star
7

knn

Simple K Nearest Neighbour Algorithm
Ruby
37
star
8

N-Gram

N-Gram generator in Ruby - http://en.wikipedia.org/wiki/N-gram
Ruby
36
star
9

TF-IDF

Term Frequency - Inverse Document Frequency in Ruby
Ruby
35
star
10

Distance-Measures

A bunch of distance measures
Ruby
31
star
11

Papyrus

Papyrus aims to hit the sweet spot between saving raw API responses to the file system and a fully fledged database like Realm.
Swift
25
star
12

Tweaker

Experiment!
Swift
21
star
13

Stripe-CardIO

Mixing Stripe and CardIO
Objective-C
21
star
14

REDPuzzleGridView

A word puzzle control, similar to Ruzzle's letter board
Objective-C
20
star
15

REDRangeSlider

Range Slider for iOS
Objective-C
19
star
16

FloatingLabelTextFieldStyle

A floating label style for SwiftUI's TextField.
Swift
16
star
17

Panel

A SwiftUI panel component similar to the iOS Airpod battery panel or the Share Wi-Fi password panel.
Swift
15
star
18

embedit

Embed media easily into your site
Ruby
14
star
19

RedUx

A super simple Swift implementation of the redux pattern making use of Swift 5.5's new async await API's.
Swift
14
star
20

Le-Code

OSX Player for the Spotify playlist "Le Code"
Objective-C
13
star
21

Campfire-Bot

Bots in your Campfires!
Ruby
13
star
22

mlp

Multi-Layer Perceptron Neural Network in Ruby
Ruby
12
star
23

rubytorrent

Port of RubyTorrent from svn
11
star
24

arrrpi_gem_builder

Turn API documentation into a wrapper
Ruby
10
star
25

Nanoleaf

Swift API client for Nanoleaf smart lights.
Swift
9
star
26

SOM

A Self Organising Map
Ruby
8
star
27

panda_cap

Capistrano recipe for Panda and MySql
Ruby
8
star
28

Date-Formatter

A little app to help with NSDateFormmater date formats
Objective-C
8
star
29

NLP-Backpack

An NLP playground
Ruby
7
star
30

Clickatell

Wrapper for http://clickatell.com
Ruby
7
star
31

CryptoIconURLBuilder

Swift
7
star
32

Spotify-Queue

Spotify play queue manager for the office
Objective-C
6
star
33

RDNotification

This class is a simple, non-instrusive alert view
Objective-C
6
star
34

ApacheBench-GUI

GUI on top of ApacheBench
Objective-C
5
star
35

i-created-something-cool

An app for all your cool apps
Ruby
5
star
36

knn_c

Knn ruby C extension
Ruby
5
star
37

Coinbase

Coinbase Swift SDK
Swift
5
star
38

REDAlertView

Experimental UIAlertView kinda thing
Objective-C
4
star
39

dbmlp

Database back Neural Network
Ruby
4
star
40

Feature-Selection

A library of feature selection algorithms.
Ruby
4
star
41

One40Proof

http://developers.140proof.com/docs/
Ruby
4
star
42

Puts-Finder

Find your lost puts
Ruby
4
star
43

Part-Of-Speech

Part of speech tagger
Ruby
4
star
44

Embedit-Gem

Wrapper for http://embedit.me
Ruby
3
star
45

is-monday-ok-

Arrange a meetup
3
star
46

Validate

A property wrapper that can validate the property it wraps.
Swift
3
star
47

TableData

Table Data is super flexible framework for building complicated table views.
Swift
3
star
48

Lumi

Swift
3
star
49

CSVDecoder

A Swift CSV decoder
Swift
3
star
50

poker

http://acm.uva.es/p/v103/10315.html
Ruby
3
star
51

panda-mysql-and-activerecord

Panda + Activerecord
3
star
52

Changelly

Changelly Swift SDK
Swift
2
star
53

Hue-Experiment

iPhone + TV + Hue
Objective-C
2
star
54

REDHTTPLogger

REDHTTPLogger makes it easy to inspect HTTP requests happening inside your iOS app without needed the debugger attached.
Objective-C
2
star
55

CV

My CV
Ruby
2
star
56

puzzles

http://www.facebook.com/careers/puzzles.php
2
star
57

robotnik

Tool for merging and compressing stylesheets and javascript files
Ruby
2
star
58

Noun-Phrase-Detection

Basic noun phrase detection
Ruby
2
star
59

Objective-Stripe

Objective C wrapper for Stripe API
Objective-C
2
star
60

Data-Prep

Helps you prepare your data for machine learning
Ruby
2
star
61

SegmentedControl

Swift
2
star
62

Nest-Dehumidifier

Ruby
2
star
63

Frequency-Distribution

http://en.wikipedia.org/wiki/Frequency_distribution
Ruby
2
star
64

Project-Euler

Problems from http://projecteuler.net
1
star
65

Test

Dummy repo for an app
1
star
66

showerthoughts-screensaver

macOS screensaver for r/showerthoughts
Swift
1
star
67

Toolbox

Just a collection of random extensions I use.
Swift
1
star
68

Magick-Identify

Wrapper around Image Magicks cl "identify"
1
star
69

Benchmarker

Instant benchmark feedback
Ruby
1
star
70

Proposal-Template

Template for my freelancing proposal
1
star
71

Arrrpi-Twitter

A Twitter wrapper generated using the arrrpi gem builder
Ruby
1
star
72

REDModel

Simple NSUserDefaults wrapper
Objective-C
1
star
73

zync

Ruby
1
star
74

Normalizer

Tool for normalizing data
Ruby
1
star
75

Bitly

Bitly
Ruby
1
star
76

doing_some_c

Trying out C
C
1
star
77

HTTP

Just some code I use for communicating and parsing API's.
Swift
1
star
78

Binary-Tree

Monkey down the binary tree
C
1
star