Class: GSLR::Model
- Inherits:
-
Object
- Object
- GSLR::Model
- Defined in:
- lib/gslr/model.rb
Instance Attribute Summary collapse
-
#coefficients ⇒ Object
readonly
Returns the value of attribute coefficients.
-
#intercept ⇒ Object
readonly
Returns the value of attribute intercept.
Instance Method Summary collapse
-
#initialize(intercept: true) ⇒ Model
constructor
A new instance of Model.
- #predict(x) ⇒ Object
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
#coefficients ⇒ Object (readonly)
Returns the value of attribute coefficients.
3 4 5 |
# File 'lib/gslr/model.rb', line 3 def coefficients @coefficients end |
#intercept ⇒ Object (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 |