0

When I copying this(below source), I always see same errors.

I used pycharm IDE and I used anaconda to install prophet(pip doesnt worked but conda-forge worked)

source: https://colab.research.google.com/drive/1NN_vY_hp9gmHfqqRi778-V_7PRRXG8ww

import pandas as pd
import plotly.graph_objs as go
import plotly.offline as py
from fbprophet import Prophet
from fbprophet.plot import plot_plotly, add_changepoints_to_plot
py.init_notebook_mode()

import numpy as np

# Confirmation, recovery, and death data sets by region worldwide
url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv'
data = pd.read_csv(url, error_bad_lines=False)

# Understanding the structure of the data set
data.head()

# Make Korea's confirmed cases timeseries dataframe

df_korea = data[data['Country/Region'] == 'Korea, South']
df_korea = df_korea.T[4:]

df_korea = df_korea.reset_index().rename(columns={'index': 'date', 155: 'confirmed'})

df_korea.tail()

# Plot Korean COVID19 confirmed cases.

fig = go.Figure()

fig.add_trace(
    go.Scatter(
        x=df_korea.date,
        y=df_korea.confirmed,
        name='Confirmed in Korea'
    )
)

fig

# Make dataframe for Facebook Prophet prediction model.
df_prophet = df_korea.rename(columns={
    'date': 'ds',
    'confirmed': 'y'
})

df_prophet.tail()

# Make Prophet model including daily seasonality
m = Prophet(
    changepoint_prior_scale=0.5, # increasing it will make the trend more flexible
    changepoint_range=0.95, # place potential changepoints in the first 98% of the time series
    yearly_seasonality=False,
    weekly_seasonality=True,
    daily_seasonality=True,
    seasonality_mode='additive'
)

m.fit(df_prophet)

future = m.make_future_dataframe(periods=7)
forecast = m.predict(future)

fig = plot_plotly(m, forecast)
py.iplot(fig)

fig = m.plot(forecast)
a = add_changepoints_to_plot(fig.gca(), m, forecast)

Error Message:

Traceback (most recent call last):
  File "C:/Users/daystd/PycharmProjects/covid_forecasting/covid.py", line 117, in <module>
    forecast = m.predict(future)
  File "F:\Anaconda\envs\pyqt_env\lib\site-packages\fbprophet\forecaster.py", line 1204, in predict
    intervals = self.predict_uncertainty(df)
  File "F:\Anaconda\envs\pyqt_env\lib\site-packages\fbprophet\forecaster.py", line 1435, in predict_uncertainty
    sim_values = self.sample_posterior_predictive(df)
  File "F:\Anaconda\envs\pyqt_env\lib\site-packages\fbprophet\forecaster.py", line 1393, in sample_posterior_predictive
    s_m=component_cols['multiplicative_terms'],
  File "F:\Anaconda\envs\pyqt_env\lib\site-packages\fbprophet\forecaster.py", line 1464, in sample_model
    trend = self.sample_predictive_trend(df, iteration)
  File "F:\Anaconda\envs\pyqt_env\lib\site-packages\fbprophet\forecaster.py", line 1501, in sample_predictive_trend
    n_changes = np.random.poisson(S * (T - 1))
  File "mtrand.pyx", line 3592, in numpy.random.mtrand.RandomState.poisson
  File "_common.pyx", line 865, in numpy.random._common.disc
  File "_common.pyx", line 414, in numpy.random._common.check_constraint
ValueError: lam value too large

Process finished with exit code 1

I cant find any information at google about this kind of errors.

I need help :(

(ValueError: lam value too large)

I think this code worked at previous version of prophet but now it doesnt.

So I want to know how to solve it or installing past prophet by conda. I'm starter of python. so I dont know how to install previous version of package with conversion of 'conda -c conda-forge fbprophet'

daystd
  • 1

1 Answers1

0

You can find the description of this error here: https://github.com/facebook/prophet/issues/1559

'ds' column should be datestamp expected by Pandas what is YYYY-MM-DD for a date. You can add this line:

# Make dataframe for Facebook Prophet prediction model.
df_prophet = df_korea.rename(columns={
    'date': 'ds',
    'confirmed': 'y'})

df_prophet['ds'] = pd.to_datetime(df_prophet['ds'])

This should solve your problem.

If anyway you want to install previous version of fbprophet, you are not able to do this using conda-forge bacause it always get the lates release.

You should download historical release from here: https://pypi.org/project/fbprophet/#history and run conda install package.tar.gz

annabitel
  • 112
  • 1
  • 1
  • 11