Class: TeaLeaves::NaiveForecast
- Defined in:
- lib/tealeaves/naive_forecast.rb
Overview
A naive model just uses the current period’s value as the prediction for the next period, i.e. F_t+1 = Y_t
Instance Attribute Summary
Attributes inherited from Forecast
Instance Method Summary collapse
-
#initialize(time_series) ⇒ NaiveForecast
constructor
Creates a naive forecasting model for the given time series.
-
#predict(n = nil) ⇒ Object
Returns a prediction for the next period, or for the next n periods.
-
#u_statistic ⇒ Object
Returns Thiel’s U Statistic.
Methods inherited from Forecast
Constructor Details
#initialize(time_series) ⇒ NaiveForecast
Creates a naive forecasting model for the given time series.
8 9 10 11 12 |
# File 'lib/tealeaves/naive_forecast.rb', line 8 def initialize(time_series) @time_series = time_series @one_step_ahead_forecasts = [nil] + time_series @one_step_ahead_forecasts.pop end |
Instance Method Details
#predict(n = nil) ⇒ Object
Returns a prediction for the next period, or for the next n periods.
22 23 24 25 26 27 28 |
# File 'lib/tealeaves/naive_forecast.rb', line 22 def predict(n=nil) if n.nil? @time_series.last else [@time_series.last] * n end end |
#u_statistic ⇒ Object
Returns Thiel’s U Statistic. By definition, this is 1 for the Naive method.
16 17 18 |
# File 'lib/tealeaves/naive_forecast.rb', line 16 def u_statistic 1 end |