当我复制这个(下面的源代码)时,我总是看到同样的错误。
我使用了 pycharm IDE,并使用 anaconda 安装了先知(pip 不起作用,但 conda-forge 起作用)
来源: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)
错误信息:
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
我在谷歌上找不到任何关于这种错误的信息。
我需要帮助 :(
(ValueError: lam 值太大)
我认为这段代码在以前版本的先知中有效,但现在不行。
所以我想知道如何解决它或通过 conda 安装过去的先知。我是python的初学者。所以我不知道如何通过“conda -c conda-forge fbprophet”的转换来安装以前版本的包