class ML::Learner::LinearRegressionLearner
Implementation of linear regression
Public Class Methods
new(dim)
click to toggle source
Intialize linear regression
@param [Integer] dim the input dimension
# File lib/method/linear_regression.rb, line 13 def initialize dim @dim = dim end
Public Instance Methods
train!(data)
click to toggle source
Train with supervised data
@param [Hash] data supervised input data (mapping from array to integer)
# 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