Class: TeaLeaves::Forecast
- Inherits:
-
Object
- Object
- TeaLeaves::Forecast
- Defined in:
- lib/tealeaves/forecast.rb
Direct Known Subclasses
ExponentialSmoothingForecast, NaiveForecast, SingleExponentialSmoothingForecast
Instance Attribute Summary collapse
-
#one_step_ahead_forecasts ⇒ Object
readonly
Returns an array of 1 step ahead forecasts.
Instance Method Summary collapse
-
#errors ⇒ Object
Returns the errors between the observed values and the one step ahead forecasts.
-
#mean_squared_error ⇒ Object
Returns the mean squared error of the forecast.
Instance Attribute Details
#one_step_ahead_forecasts ⇒ Object (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
#errors ⇒ Object
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_error ⇒ Object
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 |