<jupyter_start><jupyter_text>TBATS<jupyter_code>predictions_rolling = pd.Series()
for end_date in test_data.index:
    train_data = y[:end_date - timedelta(days=1)]
    model = TBATS(seasonal_periods=(7, 365.2425))
    model_fit = model.fit(train_data)
    pred = model_fit.forecast(steps=1)
    pred = pd.Series(pred.astype('datetime64', copy=False))
    predictions_rolling.loc[end_date] = pred.loc[end_date]


# # Fit the model
# estimator = TBATS(seasonal_periods=(7, 30.5))
# model = estimator.fit(y_to_train)

# # Forecast 365 days ahead
# y_forecast = model.forecast(steps=365)
print(model.summary())
#get the predictions and residuals
predictions = pd.Series(y_forecast, index=y_to_test.index)
residuals = y_to_test - predictions
plt.figure(figsize=(10,4))

plt.plot(y)
plt.plot(predictions)

plt.legend(('Data', 'Predictions'), fontsize=16)

plt.title('London Uber Travel Times in Seconds', fontsize=20)
plt.ylabel('Seconds', fontsize=16)
# for year in range(start_date.year,end_date.year):
#     plt.axvline(pd.to_datetime(str(year)+'-01-01'), color='k', linestyle='--', alpha=0.2)
# Mean Absolute Percentage Error (MAPE)
def mean_absolute_percentage_error(y_to_test, predictions): 
    y_to_test, predictions = np.array(y_to_test), np.array(predictions)
    return np.mean(np.abs((predictions - y_to_test)/y_to_test)) * 100

mean_absolute_percentage_error(y_to_test, predictions)
# Root Mean Square Error (RMSE)
def rmse(y_to_test, predictions):
    y_to_test, predictions = np.array(y_to_test), np.array(predictions)
    return np.sqrt(np.mean((predictions - y_to_test)**2))

rmse(y_to_test, predictions)
# Plotting trend, seasonality and residuals
decomposition = seasonal_decompose(y, model='additive', period=365)
trend    = decomposition.trend
seasonal = decomposition.seasonal
residual = decomposition.resid

fig, ax1 = plt.subplots(1, figsize=(50,10))
plt.xticks(fontsize=30)
plt.yticks(fontsize=30)

ax1.plot(y.index.unique(), residual)
ax1.set_title("Trend", fontsize=40)
ax1.set_ylabel("Mean Travel Times (Seconds)", fontsize=30)

# ax2.plot(y.index.unique(), seasonal)
# ax2.set_title("Seasonal", fontsize=40)

# ax3.plot(y.index.unique(), residual)
# ax3.set_title("Residual", fontsize=40)

fig.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14518257809062912, 'fraction_numerical': 0.030356357237131544, 'mean_word_length': 6.335483870967742, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '564803', 'license': 'Apache-2.0', 'n_tokens_mistral': 907, 'n_tokens_neox': 836, 'n_words': 145, 'path': 'Uber TS : Rolling_Forecast_Origin_Test.ipynb', 'repo_name': 'GunH-colab/UCS-21', 'size': '2273'}