Class: ML::Learner::LinearRegressionLearner
- Inherits:
-
Object
- Object
- ML::Learner::LinearRegressionLearner
- Includes:
- LinearToolbox, Toolbox
- Defined in:
- lib/method/linear_regression.rb
Overview
Implementation of linear regression
Instance Attribute Summary
Attributes included from LinearToolbox
Instance Method Summary collapse
-
#initialize(dim) ⇒ LinearRegressionLearner
constructor
Intialize linear regression.
-
#train!(data) ⇒ Object
Train with supervised data.
Methods included from LinearToolbox
Methods included from Toolbox
Constructor Details
#initialize(dim) ⇒ LinearRegressionLearner
Intialize linear regression
13 14 15 |
# File 'lib/method/linear_regression.rb', line 13 def initialize dim @dim = dim end |
Instance Method Details
#train!(data) ⇒ Object
Train with supervised data
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/method/linear_regression.rb', line 20 def train! data x = Matrix.rows(data.keys) ary_y = [] for k in data.keys ary_y << data[k] end y = Matrix.column_vector(ary_y) x_t = x.transpose x_dag = (x_t * x).inverse * x_t self.current_vector = x_dag * y end |