Class: TeaLeaves::Forecast

Inherits:
Object
  • Object
show all
Defined in:
lib/tealeaves/forecast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#one_step_ahead_forecastsObject (readonly)

Returns an array of 1 step ahead forecasts. The initial value in this array will be nil - there is no way of predicting the first value of the series.



6
7
8
# File 'lib/tealeaves/forecast.rb', line 6

def one_step_ahead_forecasts
  @one_step_ahead_forecasts
end

Instance Method Details

#errorsObject

Returns the errors between the observed values and the one step ahead forecasts.



10
11
12
13
14
# File 'lib/tealeaves/forecast.rb', line 10

def errors
  @errors ||= @time_series.zip(one_step_ahead_forecasts).map do |(observation, forecast)|
    forecast - observation if forecast && observation
  end
end

#mean_squared_errorObject

Returns the mean squared error of the forecast.



17
18
19
20
# File 'lib/tealeaves/forecast.rb', line 17

def mean_squared_error
  numerator = errors.drop(1).map {|i| i ** 2 }.inject(&:+)
  numerator / (errors.size - 1).to_f
end