ruby_linear_regression 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ruby_linear_regression.rb +12 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fdd3245c2d76d40b4e6a1992644360e0cab3d74
|
4
|
+
data.tar.gz: 3c02457473a0695ac8eae4803a8b04799e8ba4b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bea431b65d547919c489aa894d34a20a4d70b41733c9eedc32fcd6447d8feb4cd951c084f12167281e88a442d99ba799b969437a732327f7fc5ee132eb4954bf
|
7
|
+
data.tar.gz: e5242100d48114b33da5ec3e729f2b554df7258a7738583440233d85030b00a7771e7946b27f55a9b58a725e29655c3659a27ef80264bec66c49e4fbc88a24e7
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'matrix'
|
2
2
|
|
3
|
+
# RubyLinearRegression
|
3
4
|
class RubyLinearRegression
|
4
5
|
|
5
6
|
attr_reader :x,:y,:theta,:mu,:sigma
|
@@ -9,6 +10,10 @@ class RubyLinearRegression
|
|
9
10
|
@sigma = 1
|
10
11
|
end
|
11
12
|
|
13
|
+
# Loads and normalizes the training data, must be called prior to training.
|
14
|
+
# Arguments:
|
15
|
+
# x_data: (Two dimensiolnal array with the independent variables of your training data)
|
16
|
+
# y_data: (Array with the dependent variables of your training data)
|
12
17
|
def load_training_data x_data, y_data
|
13
18
|
|
14
19
|
# normalize the x_data
|
@@ -24,8 +29,8 @@ class RubyLinearRegression
|
|
24
29
|
@theta = Matrix[[0],[0]]
|
25
30
|
end
|
26
31
|
|
32
|
+
# Compute the mean squared cost / error function
|
27
33
|
def compute_cost
|
28
|
-
# Compute the mean squared cost / error function
|
29
34
|
# First use matrix multiplication and vector subtracton to find errors
|
30
35
|
errors = (@x * @theta) - @y
|
31
36
|
|
@@ -38,6 +43,7 @@ class RubyLinearRegression
|
|
38
43
|
return mean_square_error
|
39
44
|
end
|
40
45
|
|
46
|
+
# Calculate the optimal theta using the normal equation
|
41
47
|
def train_normal_equation
|
42
48
|
# Calculate the optimal theta using the normal equation
|
43
49
|
# theta = ( X' * X )^1 * X' * y
|
@@ -46,6 +52,11 @@ class RubyLinearRegression
|
|
46
52
|
return @theta
|
47
53
|
end
|
48
54
|
|
55
|
+
# Makes a prediction based on your trained model.
|
56
|
+
# train_normal_equation must be called prior to making a prediction.
|
57
|
+
#
|
58
|
+
# Arguments:
|
59
|
+
# data: (Array of independent variables to base your prediction on)
|
49
60
|
def predict data
|
50
61
|
|
51
62
|
# normalize
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_linear_regression
|
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
|
- Soren Blond Daugaard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10
|
11
|
+
date: 2017-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "An implementation of a linear regression machine learning algorithm
|
14
14
|
implemented in Ruby.\n This algorithm uses Ruby's Matrix implementation
|