Module: Prophet
- Defined in:
- lib/prophet.rb,
lib/prophet/plot.rb,
lib/prophet/version.rb,
lib/prophet/holidays.rb,
lib/prophet/forecaster.rb,
lib/prophet/stan_backend.rb
Defined Under Namespace
Modules: Holidays, Plot Classes: Error, Forecaster, StanBackend
Constant Summary collapse
- VERSION =
"0.2.1"
Class Method Summary collapse
-
.forecast(series, count: 10) ⇒ Object
to add time support in future, see github.com/ankane/prophet/commit/06e3562835cbcf06b8431f3a91fe2618d4703eb7.
- .new(**kwargs) ⇒ Object
Class Method Details
.forecast(series, count: 10) ⇒ Object
to add time support in future, see github.com/ankane/prophet/commit/06e3562835cbcf06b8431f3a91fe2618d4703eb7
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/prophet.rb', line 26 def self.forecast(series, count: 10) raise ArgumentError, "Series must have at least 10 data points" if series.size < 10 keys = series.keys bad_key = keys.find { |k| !k.is_a?(Date) } raise ArgumentError, "Expected Date, got #{bad_key.class.name}" if bad_key week = keys.map { |k| k.wday }.uniq.size == 1 month = keys.all? { |k| k.day == 1 } quarter = month && keys.all? { |k| k.month % 3 == 1 } year = quarter && keys.all? { |k| k.month == 1 } freq = if year "YS" elsif quarter "QS" elsif month "MS" elsif week "W" else "D" end df = Rover::DataFrame.new({"ds" => series.keys, "y" => series.values}) m = Prophet.new m.logger.level = ::Logger::FATAL # no logging m.fit(df) future = m.make_future_dataframe(periods: count, include_history: false, freq: freq) forecast = m.predict(future) forecast[["ds", "yhat"]].to_a.map { |v| [v["ds"].to_date, v["yhat"]] }.to_h end |
.new(**kwargs) ⇒ Object
20 21 22 |
# File 'lib/prophet.rb', line 20 def self.new(**kwargs) Forecaster.new(**kwargs) end |