Esempio n. 1
0
def test_automatic_changepoints_manning():
    df = pd.read_csv("examples/example_wp_log_peyton_manning.csv")
    m = PMProphet(df, auto_changepoints=True, growth=True, intercept=True, name="model")
    m.add_seasonality(seasonality=365, fourier_order=3)
    m.fit(method=Sampler.METROPOLIS)
    m.predict(60, alpha=0.2, include_history=True, plot=True)
    m.plot_components(intercept=False)
def pm_prophet(train,test, column):
    # Fit both growth and intercept
    train = train.reset_index()
    train['date'] = pd.to_datetime(train['date'])
    train.columns = ['ds', 'y']
    start = time.time()
    m = PMProphet(train, growth=True, intercept=True, n_change_points=2, name='model')
    # Add monthly seasonality (order: 3)
    m.add_seasonality(seasonality=30, order=3)
    # Add weekly seasonality (order: 3)
    m.add_seasonality(seasonality=7, order=3)
    # Fit the model (using NUTS, 1e+4 samples and no MAP init)
    m.fit(
        draws=10**4,
        method='NUTS',
        map_initialization=False,
    )
    ddf = m.predict(7, alpha=0.4, include_history=True, plot=True)
    m.plot_components(
        intercept=False,
    )
    pred = inverse_transform(ddf[-7:], 'y_hat')
    rmse_pm = sqrt(mean_squared_error(test, pred))
    end = time.time()
    time_fb = end - start
    print('\n The total RMSE using FB prophet : %.3f' % rmse_pm)
    result.loc[len(result)] = [column, 'pm_prophet', rmse_pm, time_pm] 
    #test_plt((20,10), test_df, predictions, column, 'pmprophet')
    result_plots['pm_prophet'] = pred 
    result.loc[len(result)] = [' ', ' ', ' ', ' ']
Esempio n. 3
0
def test_manning():
    df = pd.read_csv("examples/example_wp_log_peyton_manning.csv")
    df = df.head(180)
    m = PMProphet(df, growth=True, intercept=True, name="model")
    m.add_seasonality(seasonality=30, fourier_order=3)
    m.fit(method=Sampler.METROPOLIS, draws=2000)
    m.predict(60, alpha=0.2, include_history=True, plot=True)
    m.plot_components(intercept=False)
Esempio n. 4
0
def test_manning_reduced_six_months():
    df = pd.read_csv("examples/example_wp_log_peyton_manning.csv")
    df = df.head(180)
    m = PMProphet(df, auto_changepoints=True, growth=True, intercept=True, name="model")
    m.add_seasonality(seasonality=7, fourier_order=3)
    m.add_seasonality(seasonality=30, fourier_order=3)
    m.fit()
    m.predict(60, alpha=0.2, include_history=True, plot=True)
    m.plot_components(intercept=False)
Esempio n. 5
0
def test_seasonality_shape():
    """
    Verify that that the size of the fourier timeseries is correct
    """
    df = pd.read_csv("examples/example_wp_log_peyton_manning.csv")
    m = PMProphet(df, auto_changepoints=True, growth=True, intercept=True, name="model")
    m.add_seasonality(seasonality=3, fourier_order=3, mode=Seasonality.ADDITIVE)
    m.add_seasonality(seasonality=30, fourier_order=3, mode=Seasonality.ADDITIVE)
    m.fit(method=Sampler.METROPOLIS, draws=2000)
    m.predict(60, alpha=0.2, include_history=True, plot=False)
    assert m.trace['seasonality_model'].shape[1] == 12  # (3 + 3) * 2 (sin and cos)
Esempio n. 6
0
def test_multiplicative_seasonality():
    z = np.sin(np.linspace(0, 200, 200)) * np.linspace(0, 200, 200)
    df = pd.DataFrame()
    df["ds"] = pd.date_range(start="2018-01-01", periods=200)
    df["y"] = z
    m = PMProphet(df, auto_changepoints=False, growth=True, intercept=False, name="model")
    with m.model:
        m.priors['growth'] = pm.Constant('growth_model', 1)
    m.add_seasonality(seasonality=3.14 * 2, fourier_order=3, mode=Seasonality.MULTIPLICATIVE)
    m.fit()
    m.predict(60, alpha=0.2, include_history=True, plot=True)
    m.plot_components(intercept=False)
Esempio n. 7
0
def test_multiplicative_seasonality():
    df = pd.read_csv("examples/example_wp_log_peyton_manning.csv")
    m = PMProphet(df,
                  auto_changepoints=True,
                  growth=True,
                  intercept=True,
                  name="model")
    m.add_seasonality(seasonality=365,
                      fourier_order=3,
                      mode=Seasonality.MULTIPLICATIVE)
    m.fit(method=Sampler.METROPOLIS, draws=2000)
    m.predict(60, alpha=0.2, include_history=True, plot=True)
    m.plot_components(intercept=False)