df = load_california_electricity_demand(train_only=True)

# Log transform the target variable
df['y'] = df.y.apply(np.log)

# ## Prophet (with more complicated seasonality)
# FB Prophet model, splitting intra-day seasonalities into four subgroups:
# - summer weekday
# - summer weekend
# - winter weekday
# - winter weekend

model = seasonal_daily_prophet_model(df)

future = model.make_future_dataframe(periods=8760, freq='H')
seasonal_future = add_season_weekday_indicators(future)

forecast = model.predict(seasonal_future)

# Reverse the log transform on predictions
forecast['yhat'] = forecast.yhat.apply(np.exp)

# ## Write
# Write the forecast values to csv
DIR = 'data/forecasts/'

if not os.path.exists(DIR):
    os.makedirs(DIR)

forecast[['ds', 'yhat']].to_csv(DIR + 'prophet_complex_log.csv', index=False)
Ejemplo n.º 2
0
from sts.data.loader import load_california_electricity_demand

# Load all available data for training

df = load_california_electricity_demand()

# Take log transform for fully multiplicative model
df['y'] = df.y.apply(np.log)

# Fit best current model

model = seasonal_daily_prophet_model(df)

# Make predictions for one year ahead of most recent training data

future = add_season_weekday_indicators(
    model.make_future_dataframe(periods=24 * 365, freq='H'))

forecast = model.predict(future)

samples = model.predictive_samples(future)

# Reverse log transform
predictions = np.exp(samples['yhat'])

prediction_df = (future.merge(
    pd.DataFrame(predictions), left_index=True, right_index=True).drop(
        [
            'winter_weekday', 'winter_weekend', 'summer_weekday',
            'summer_weekend'
        ],
        axis='columns')[future.ds.dt.date >= datetime.date.today()])