Jupyter Notebook运行遇TypeError报错,求有效解决方法
解决Prophet初始化时的TypeError问题
根据报错信息,核心问题是**__init__() got an unexpected keyword argument 'yearly_seasonality'**,这是因为新版本的Prophet(原fbprophet)已调整了初始化参数规则,yearly_seasonality不再作为直接的初始化参数使用。
修复步骤:
- 先确认安装正确的官方包:原
fbprophet已迁移更名为prophet,卸载旧包重新安装:pip uninstall fbprophet -y pip install prophet - 修正初始化代码:
旧写法(触发报错):
新版本正确写法:from prophet import Prophet model = Prophet(yearly_seasonality=True)
方式1:使用默认配置(默认已开启年、周季节性)
方式2:通过model = Prophet()add_seasonality自定义季节性参数
方式3:关闭默认季节性后手动添加自定义规则model = Prophet() model.add_seasonality(name='yearly', period=365.25, fourier_order=10)model = Prophet(yearly_seasonality=False) model.add_seasonality(name='custom_yearly', period=365.25, fourier_order=15)
额外排查点:
- 检查代码中是否还有其他废弃参数(如
weekly_seasonality、daily_seasonality的旧用法),新版本推荐通过add_seasonality灵活配置。 - 确认Jupyter Notebook内核使用的Python环境已安装新版
prophet,避免环境不一致导致的版本冲突。
内容的提问来源于stack exchange,提问作者brian manning
相关产品推荐
相关产品推荐

