ruby_linear_regression 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_linear_regression.rb +6 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cba2118afd13d70db9b3507b3cfee6a814b2e02
|
4
|
+
data.tar.gz: ba65dab424b629bb81f04811c1ddf4e24a910a85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a4a4ebd99923983194a69c1cfeae6334ef0e6a7b9c5caa47c3f55ee92bddde8f8c30e735fd8b44bd3c38d4567ce4b6f3e0f1026277ebd1ecaac66b68df45b02
|
7
|
+
data.tar.gz: 02c69eb19ac21ce780767e83c1e239cb11e30aa3ac75837fff3404793e26ae429d28a8633147146f52ec47d83cad3a1a6bc3624ff02fd4116d8133195bbe5031
|
@@ -3,7 +3,7 @@ require 'matrix'
|
|
3
3
|
# RubyLinearRegression
|
4
4
|
class RubyLinearRegression
|
5
5
|
|
6
|
-
attr_reader :x,:y,:theta,:mu,:sigma
|
6
|
+
attr_reader :x,:y,:theta,:mu,:sigma, :lambda, :normalize
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@mu = 0
|
@@ -14,10 +14,12 @@ class RubyLinearRegression
|
|
14
14
|
# Arguments:
|
15
15
|
# x_data: (Two dimensiolnal array with the independent variables of your training data)
|
16
16
|
# y_data: (Array with the dependent variables of your training data)
|
17
|
-
def load_training_data x_data, y_data
|
17
|
+
def load_training_data x_data, y_data, normalize = true
|
18
|
+
|
19
|
+
@normalize = normalize
|
18
20
|
|
19
21
|
# normalize the x_data
|
20
|
-
x_data = normalize_data( x_data )
|
22
|
+
x_data = normalize_data( x_data ) if @normalize
|
21
23
|
|
22
24
|
# add 1 column to our data
|
23
25
|
x_data = x_data.map { |r| [1].concat(r) }
|
@@ -82,7 +84,7 @@ class RubyLinearRegression
|
|
82
84
|
# normalize
|
83
85
|
data.each_index do |i|
|
84
86
|
data[i] = (data[i] - @mu[i]) / @sigma[i].to_f
|
85
|
-
end
|
87
|
+
end if @normalize
|
86
88
|
|
87
89
|
# add 1 column to prediction data
|
88
90
|
data = [1].concat( data )
|