Cesar
Cesar

Reputation: 585

Timeseries prediction using prophet (issubdtype from `float`)

I am trying to use prophet package to predict a time series:

First I merge Month and Day into a column:

df1['Date'] = pd.to_datetime(df1.Ano.astype(str) + '-' + df1.Meses.astype(str))

My dataframe :

          Date     Values
11259 2017-01-01  23.818044
11286 2017-02-01  20.275252
11313 2017-03-01  22.347278
11340 2017-04-01  23.837490
11367 2017-05-01  23.460605
11394 2017-06-01  22.307115
11421 2017-07-01  23.643994
11448 2017-08-01  23.791720
11475 2017-09-01  23.643933
11502 2017-10-01  20.771269
11529 2017-11-01  21.317947
11556 2017-12-01  22.361570
33723 2018-01-01  24.336259
33750 2018-02-01  19.926928
33777 2018-03-01  22.714901
33804 2018-04-01  23.605119
33831 2018-05-01  23.653298
33858 2018-06-01  23.052182
33885 2018-07-01  24.377920
33912 2018-08-01  24.576733
33939 2018-09-01  24.376775
33966 2018-10-01  21.256970
33993 2018-11-01  21.969202
34020 2018-12-01  22.970637

Then I tried to use the following function:

sub_model = Prophet(interval_width=0.95)
sub_model.fit(df1)

Then I got the following error:

KeyError: 'y'

During handling of the above exception, another exception occurred:

    KeyError                                  Traceback (most recent call last)
<ipython-input-6-a31a513027be> in <module>()
     31 
     32 sub_model = Prophet(interval_width=0.95)
---> 33 sub_model.fit(df1)
     34

Is there anything wrong on my Year-month-day column that conflicts with prophet function?

Update: The first solution, as Vasil suggested, was to change date column name to 'ds' and the variable column to 'y'.

Now, it appears the error message:

 INFO:fbprophet.forecaster:n_changepoints greater than number of observations.Using 18.0.

That reffers to this function:

# the history.
hist.size <- floor(nrow(m$history) * .8)
if (m$n.changepoints + 1 > hist.size) {
  m$n.changepoints <- hist.size - 1
  message('n.changepoints greater than number of observations. Using ',
          m$n.changepoints)
}

Update: The second problem was solved adding n_changepoints argument suggested by alec_djinn

The last problem is the second message:

Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.

Upvotes: 0

Views: 3137

Answers (1)

Vasil Yordanov
Vasil Yordanov

Reputation: 417

By default prophet assumes you have daily data. In your case it is monthly though.

If you want to predict monthly data you should write something like this:

sub_model  = Prophet(weekly_seasonality=False, daily_seasonality=False).fit(df1)
future = sub_model.make_future_dataframe(periods=1, freq='M')
fcst = sub_model.predict(future)

Another important point are the names of the columns you are passing into phrophet. Your date column must be named 'ds' and the variable column which you want to predict must be 'y'

Upvotes: 4

Related Questions