ankane/prophet-ruby

Help: How to get components values?

Closed this issue · 4 comments

Hello,

I am looking for a way to get the components of the forecasted series.

I know I could use this but I need the numeric values, not the chart.

m.plot_components(forecast).savefig("components.png")

image

Inspecting the code I found this

model.predict(future_days(days: days))
puts model.seasonalities.inspect

but the output is this

{"weekly"=>{:period=>7, :fourier_order=>3, :prior_scale=>10.0, :mode=>"multiplicative", :condition_name=>nil}}
{"weekly"=>{:period=>7, :fourier_order=>3, :prior_scale=>10.0, :mode=>"multiplicative", :condition_name=>nil}}

Hi @leoplct, the data frame returned from model.predict() should have it.

@ankane The method .seasonalities doesn't exist.

r = model.predict(future_days(days: days))
puts r.seasonalities.inspect
/app/services/forecaster/forecaster.rb:8:in `results': undefined method `seasonalities' for                      ds               trend          yhat_lower          yhat_upper         trend_lower (NoMethodError)
2020-01-01 00:00:00 UTC          132.457668  102.54412310794025   160.7679458245698          132.457668
2020-01-02 00:00:00 UTC  135.52352290909093  106.29359243905199  163.72024324319386  135.52352290909093
2020-01-03 00:00:00 UTC  138.58937782025072   108.6678132212479  169.89344531863384  138.58937782025072
2020-01-04 00:00:00 UTC  141.65523271340436  110.02777864484085  171.52578446670833  141.65523271340436
2020-01-05 00:00:00 UTC   144.7210876055361  114.07941973515894  173.76046504415518   144.7210876055361
                    ...                 ...                 ...                 ...                 ...
2020-02-07 00:00:00 UTC  245.89429893658695  215.64588805741883   277.5255988074532  245.89427912161068
2020-02-08 00:00:00 UTC  248.96015382504646  219.92458120979668  279.48258544843526  248.96013285568122
2020-02-09 00:00:00 UTC   252.0260087135059  225.84879229851205   281.4402568223808  252.02598634948285
2020-02-10 00:00:00 UTC  255.09186360196537  226.73538315722791   287.3103036278492   255.0918399893096
2020-02-11 00:00:00 UTC   258.1577184904248   228.4267107916969   285.5872656861613  258.15769368316364

       trend_upper  Amazon events  Amazon events_lower  Amazon events_upper  holidays  holidays_lower  holidays_upper
        132.457668            0.0                  0.0                  0.0       0.0             0.0             0.0
135.52352290909093            0.0                  0.0                  0.0       0.0             0.0             0.0
138.58937782025072            0.0                  0.0                  0.0       0.0             0.0             0.0
141.65523271340436            0.0                  0.0                  0.0       0.0             0.0             0.0
 144.7210876055361            0.0                  0.0                  0.0       0.0             0.0             0.0
               ...            ...                  ...                  ...       ...             ...             ...
245.89431759518342            0.0                  0.0                  0.0       0.0             0.0             0.0
248.96017402538914            0.0                  0.0                  0.0       0.0             0.0             0.0
252.02602978164828            0.0                  0.0                  0.0       0.0             0.0             0.0
255.09188646235285            0.0                  0.0                  0.0       0.0             0.0             0.0
 258.1577422432756            0.0                  0.0                  0.0       0.0             0.0             0.0

multiplicative_terms  multiplicative_terms_lower  multiplicative_terms_upper  col  col_lower  col_upper  additive_terms
                 0.0                         0.0                         0.0  0.0        0.0        0.0             0.0
                 0.0                         0.0                         0.0  0.0        0.0        0.0             0.0
                 0.0                         0.0                         0.0  0.0        0.0        0.0             0.0
                 0.0                         0.0                         0.0  0.0        0.0        0.0             0.0
                 0.0                         0.0                         0.0  0.0        0.0        0.0             0.0
                 ...                         ...                         ...  ...        ...        ...             ...
                 0.0                         0.0                         0.0  0.0        0.0        0.0             0.0
                 0.0                         0.0                         0.0  0.0        0.0        0.0             0.0
                 0.0                         0.0                         0.0  0.0        0.0        0.0             0.0
                 0.0                         0.0                         0.0  0.0        0.0        0.0             0.0
                 0.0                         0.0                         0.0  0.0        0.0        0.0             0.0

additive_terms_lower  additive_terms_upper                yhat
                 0.0                   0.0          132.457668
                 0.0                   0.0  135.52352290909093
                 0.0                   0.0  138.58937782025072
                 0.0                   0.0  141.65523271340436
                 0.0                   0.0   144.7210876055361
                 ...                   ...                 ...
                 0.0                   0.0  245.89429893658695
                 0.0                   0.0  248.96015382504646
                 0.0                   0.0   252.0260087135059
                 0.0                   0.0  255.09186360196537
                 0.0                   0.0   258.1577184904248:Rover::DataFrame

    puts r.seasonalities.inspect
          ^^^^^^^^^^^^^^


@ankane Any news on this?

If there's weekly seasonality, there will be weekly, weekly_lower, and weekly_upper columns in the data frame.