Class: FlexStationData::LinearRegression
- Inherits:
-
Object
- Object
- FlexStationData::LinearRegression
- Defined in:
- lib/flex_station_data/linear_regression.rb
Instance Attribute Summary collapse
-
#min_r_squared ⇒ Object
readonly
Returns the value of attribute min_r_squared.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(x, y, min_r_squared: 0.0) ⇒ LinearRegression
constructor
A new instance of LinearRegression.
- #intercept ⇒ Object
- #quality ⇒ Object
- #r_squared ⇒ Object
- #slope ⇒ Object
Constructor Details
#initialize(x, y, min_r_squared: 0.0) ⇒ LinearRegression
Returns a new instance of LinearRegression.
10 11 12 13 14 |
# File 'lib/flex_station_data/linear_regression.rb', line 10 def initialize(x, y, min_r_squared: 0.0, **) @x = x @y = y @min_r_squared = min_r_squared.to_f end |
Instance Attribute Details
#min_r_squared ⇒ Object (readonly)
Returns the value of attribute min_r_squared.
8 9 10 |
# File 'lib/flex_station_data/linear_regression.rb', line 8 def min_r_squared @min_r_squared end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
8 9 10 |
# File 'lib/flex_station_data/linear_regression.rb', line 8 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
8 9 10 |
# File 'lib/flex_station_data/linear_regression.rb', line 8 def y @y end |
Instance Method Details
#intercept ⇒ Object
20 21 22 |
# File 'lib/flex_station_data/linear_regression.rb', line 20 def intercept coefficients[0] end |
#quality ⇒ Object
30 31 32 |
# File 'lib/flex_station_data/linear_regression.rb', line 30 def quality "poor fit" if r_squared.present? && r_squared < min_r_squared end |
#r_squared ⇒ Object
24 25 26 27 28 |
# File 'lib/flex_station_data/linear_regression.rb', line 24 def r_squared @r_squared ||= line_fit.rSquared rescue TypeError nil end |
#slope ⇒ Object
16 17 18 |
# File 'lib/flex_station_data/linear_regression.rb', line 16 def slope coefficients[1] end |