ml.rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+
2
+ source 'https://rubygems.org'
3
+
4
+ gem 'gsl'
data/Gemfile.lock ADDED
@@ -0,0 +1,12 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ gsl (1.14.7)
5
+ narray (>= 0.5.9)
6
+ narray (0.6.0.1)
7
+
8
+ PLATFORMS
9
+ ruby
10
+
11
+ DEPENDENCIES
12
+ gsl
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ml.rb
2
+ =====
3
+
4
+ A bunch of machine learning algorithms, written in Ruby
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/data/ex1data1.txt ADDED
@@ -0,0 +1,97 @@
1
+ 6.1101,17.592
2
+ 5.5277,9.1302
3
+ 8.5186,13.662
4
+ 7.0032,11.854
5
+ 5.8598,6.8233
6
+ 8.3829,11.886
7
+ 7.4764,4.3483
8
+ 8.5781,12
9
+ 6.4862,6.5987
10
+ 5.0546,3.8166
11
+ 5.7107,3.2522
12
+ 14.164,15.505
13
+ 5.734,3.1551
14
+ 8.4084,7.2258
15
+ 5.6407,0.71618
16
+ 5.3794,3.5129
17
+ 6.3654,5.3048
18
+ 5.1301,0.56077
19
+ 6.4296,3.6518
20
+ 7.0708,5.3893
21
+ 6.1891,3.1386
22
+ 20.27,21.767
23
+ 5.4901,4.263
24
+ 6.3261,5.1875
25
+ 5.5649,3.0825
26
+ 18.945,22.638
27
+ 12.828,13.501
28
+ 10.957,7.0467
29
+ 13.176,14.692
30
+ 22.203,24.147
31
+ 5.2524,-1.22
32
+ 6.5894,5.9966
33
+ 9.2482,12.134
34
+ 5.8918,1.8495
35
+ 8.2111,6.5426
36
+ 7.9334,4.5623
37
+ 8.0959,4.1164
38
+ 5.6063,3.3928
39
+ 12.836,10.117
40
+ 6.3534,5.4974
41
+ 5.4069,0.55657
42
+ 6.8825,3.9115
43
+ 11.708,5.3854
44
+ 5.7737,2.4406
45
+ 7.8247,6.7318
46
+ 7.0931,1.0463
47
+ 5.0702,5.1337
48
+ 5.8014,1.844
49
+ 11.7,8.0043
50
+ 5.5416,1.0179
51
+ 7.5402,6.7504
52
+ 5.3077,1.8396
53
+ 7.4239,4.2885
54
+ 7.6031,4.9981
55
+ 6.3328,1.4233
56
+ 6.3589,-1.4211
57
+ 6.2742,2.4756
58
+ 5.6397,4.6042
59
+ 9.3102,3.9624
60
+ 9.4536,5.4141
61
+ 8.8254,5.1694
62
+ 5.1793,-0.74279
63
+ 21.279,17.929
64
+ 14.908,12.054
65
+ 18.959,17.054
66
+ 7.2182,4.8852
67
+ 8.2951,5.7442
68
+ 10.236,7.7754
69
+ 5.4994,1.0173
70
+ 20.341,20.992
71
+ 10.136,6.6799
72
+ 7.3345,4.0259
73
+ 6.0062,1.2784
74
+ 7.2259,3.3411
75
+ 5.0269,-2.6807
76
+ 6.5479,0.29678
77
+ 7.5386,3.8845
78
+ 5.0365,5.7014
79
+ 10.274,6.7526
80
+ 5.1077,2.0576
81
+ 5.7292,0.47953
82
+ 5.1884,0.20421
83
+ 6.3557,0.67861
84
+ 9.7687,7.5435
85
+ 6.5159,5.3436
86
+ 8.5172,4.2415
87
+ 9.1802,6.7981
88
+ 6.002,0.92695
89
+ 5.5204,0.152
90
+ 5.0594,2.8214
91
+ 5.7077,1.8451
92
+ 7.6366,4.2959
93
+ 5.8707,7.2029
94
+ 5.3054,1.9869
95
+ 8.2934,0.14454
96
+ 13.394,9.0551
97
+ 5.4369,0.61705
data/lib/ext.rb ADDED
@@ -0,0 +1,14 @@
1
+
2
+ require 'gsl'
3
+
4
+ include GSL
5
+
6
+ Vector.class_eval do
7
+ def self.ones(n)
8
+ Vector.alloc(n).set_all(1)
9
+ end
10
+
11
+ def self.zeroes(n)
12
+ Vector.alloc(n).set_all(0)
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ class LinearRegression
2
+ # Parameters:
3
+ #
4
+ # x - m by n matrix
5
+ # y - vector of length m
6
+ #
7
+ # TODO (farleyknight@gmail.com): If x happens to be a vector
8
+ # we should use the, presumably, less costly computation of
9
+ # using GSL::Fit::linear(x, y) over GSL::MultiFit::linear(X, y)
10
+ def fit(x, y)
11
+ raise "" unless x.is_a? Matrix
12
+ raise "" unless y.is_a? Vector and y.length == x.shape[1]
13
+ end
14
+
15
+ # x - vector of length n
16
+ def predict(x)
17
+
18
+ end
19
+ end
data/lib/ml/version.rb ADDED
@@ -0,0 +1,4 @@
1
+
2
+ module Ml
3
+ VERSION = "0.0.1"
4
+ end
data/lib/ml.rb ADDED
@@ -0,0 +1,4 @@
1
+
2
+ module Ml
3
+
4
+ end
data/ml.rb.gemspec ADDED
@@ -0,0 +1,19 @@
1
+
2
+ Gem::Specification.new do |s|
3
+ s.name = 'ml.rb'
4
+ s.version = '0.0.1'
5
+ s.date = '2012-08-14'
6
+ s.summary = "A bunch of machine learning algorithms, written in Ruby"
7
+ s.description = "A bunch of machine learning algorithms, written in Ruby"
8
+ s.authors = ["Farley Knight"]
9
+ s.email = 'farleyknight@gmail.com'
10
+
11
+ s.homepage = 'https://github.com/farleyknight/ml.rb'
12
+
13
+ s.add_development_dependency "bundler", ">= 1.0.0"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
17
+ s.require_path = 'lib'
18
+ end
19
+
@@ -0,0 +1,6 @@
1
+
2
+ describe "Linear regression" do
3
+ it "should match the scores on ml-class.org" do
4
+ data = CSV.read('data/ex1data1.txt')
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ml.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Farley Knight
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ description: A bunch of machine learning algorithms, written in Ruby
31
+ email: farleyknight@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - README.md
40
+ - Rakefile
41
+ - data/ex1data1.txt
42
+ - lib/ext.rb
43
+ - lib/linear_regression.rb
44
+ - lib/ml.rb
45
+ - lib/ml/version.rb
46
+ - ml.rb.gemspec
47
+ - spec/linear_regression_spec.rb
48
+ homepage: https://github.com/farleyknight/ml.rb
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: A bunch of machine learning algorithms, written in Ruby
72
+ test_files: []