Class: FlexStationData::LinearRegression

Inherits:
Object
  • Object
show all
Defined in:
lib/flex_station_data/linear_regression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_squaredObject (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

#xObject (readonly)

Returns the value of attribute x.



8
9
10
# File 'lib/flex_station_data/linear_regression.rb', line 8

def x
  @x
end

#yObject (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

#interceptObject



20
21
22
# File 'lib/flex_station_data/linear_regression.rb', line 20

def intercept
  coefficients[0]
end

#qualityObject



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_squaredObject



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

#slopeObject



16
17
18
# File 'lib/flex_station_data/linear_regression.rb', line 16

def slope
  coefficients[1]
end