商业数据挖掘FaceBook工具(「BI」)jetrail

    技术2022-07-10  89

    import pandas as pd import numpy as np # 数据加载 train = pd.read_csv('./train.csv') print(train.head()) # 转换为pandas中的日期格式 train['Datetime'] = pd.to_datetime(train.Datetime, format='%d-%m-%Y %H:%M') # 将Datetime作为train的索引 train.index = train.Datetime # 去掉ID, Datetime train.drop(['ID', 'Datetime'], axis=1, inplace=True) # 按天进行采样 daily_train = train.resample('D').sum() daily_train['ds'] = daily_train.index daily_train['y'] = daily_train.Count daily_train.drop(['Count'], axis=1, inplace=True) print(daily_train) from fbprophet import Prophet # 拟合prophet模型 m = Prophet(yearly_seasonality=True, seasonality_prior_scale=0.1) # 使用fit完成拟合 m.fit(daily_train) # 预测未来7个月,213天 future = m.make_future_dataframe(periods=213) print(future.tail()) # 预测未来,prophet考虑了 周、月,还有holidays forecast = m.predict(future) m.plot(forecast) # 成分分析 m.plot_components(forecast)
    Processed: 0.126, SQL: 12