Class: GSLR::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/gslr/model.rb

Direct Known Subclasses

OLS, Ridge

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(intercept: true) ⇒ Model

Returns a new instance of Model.



5
6
7
# File 'lib/gslr/model.rb', line 5

def initialize(intercept: true)
  @fit_intercept = intercept
end

Instance Attribute Details

#coefficientsObject (readonly)

Returns the value of attribute coefficients.



3
4
5
# File 'lib/gslr/model.rb', line 3

def coefficients
  @coefficients
end

#interceptObject (readonly)

Returns the value of attribute intercept.



3
4
5
# File 'lib/gslr/model.rb', line 3

def intercept
  @intercept
end

Instance Method Details

#predict(x) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/gslr/model.rb', line 9

def predict(x)
  if numo?(x)
    x.dot(@coefficients) + @intercept
  else
    x.map do |xi|
      xi.zip(@coefficients).map { |xii, c| xii * c }.sum + @intercept
    end
  end
end