<jupyter_start><jupyter_text>Assignment- Use the same data you chose for the previous lesson, or get new data.- Do train/test split. Report your mean absolute error on the train and test set, for these forecasts:  - Mean Baseline  - Naive Baseline (Last Observation)  - Prophet forecast (you can choose the parameters or use the defaults)- Do time series cross-validation, using these Prophet functions:  - cross_validation  - performance_metrics  - plot_cross_validation_metric- Commit your notebook to your fork of the GitHub repo. Stretch Challenges- **Share your visualizations on Slack!**- Use the Wikimedia Pageviews API to get data.- [Get daily weather station data](https://www.ncdc.noaa.gov/cdo-web/search) from the NOAA (National Oceanic and Atmospheric Administration). User Prophet to forecast the weather for your local area. - Adjust your forecasts with Prophet's [changepoints](https://facebook.github.io/prophet/docs/trend_changepoints.html) and [holidays](https://facebook.github.io/prophet/docs/seasonality,_holiday_effects,_and_regressors.html) options. In addition to Prophet's documentation, read <NAME>'s blog post, [Time Series Analysis in Python](https://towardsdatascience.com/time-series-analysis-in-python-an-introduction-70d5a5b1d52a). **How do these parameters affect your error metrics?**- Learn more about how Prophet works. Read the [tweestorm with animated GIFs](https://twitter.com/seanjtaylor/status/1123278380369973248) by Prophet developer <NAME>, or his [research paper](https://peerj.com/preprints/3190/).<jupyter_code>import pandas as pd
from pandas.tseries.holiday import USFederalHolidayCalendar as calendar
df = pd.read_csv('/Users/ridleyleisy/Documents/lambda/unit_two/DS-Unit-2-Regression-1/module2-evaluating-forecasts/walmart-recruiting-store-sales-forecasting/train.csv')
cal = calendar()
holidays = cal.holidays(start=df['Date'].min(), end=df['Date'].max())
df['holiday'] = df['Date'].isin(holidays)
df.head()<jupyter_output><empty_output><jupyter_text>Train/test splitOnly looking at store 13<jupyter_code>train['Store'].value_counts().head()
train = df.loc[(df['Date'] < '2012-01-01') & (df['Store'] == 12)].copy()
test = df.loc[(df['Date'] >= '2012-01-01')& (df['Store'] == 12)].copy()
train.head()<jupyter_output><empty_output><jupyter_text>Mean baseline<jupyter_code>train['mean_baseline'] = train['Weekly_Sales'].mean()
test['mean_baseline'] = train['Weekly_Sales'].mean()
train<jupyter_output><empty_output><jupyter_text>Naive baseline<jupyter_code>train['naive_baseline'] = train['Weekly_Sales'].shift(1).bfill()
test['naive_baseline'] = train['Weekly_Sales'].iloc[-1]
train.head()<jupyter_output><empty_output><jupyter_text>Errors<jupyter_code>from sklearn.metrics import mean_absolute_error
cols = {'Date':'ds','Weekly_Sales':'y'}
test.rename(cols, axis=1, inplace=True)
train.rename(cols, axis=1, inplace=True)
mean_absolute_error(train['y'],train['mean_baseline'])
mean_absolute_error(train['y'],train['naive_baseline'])
mean_absolute_error(test['y'],test['mean_baseline'])
mean_absolute_error(test['y'],test['naive_baseline'])<jupyter_output><empty_output><jupyter_text>Prophet<jupyter_code>cal = calendar()
holidays = cal.holidays(start=df['Date'].min(), end=df['Date'].max())
train[train['ds'].isin(holidays)]
holidays = train[['ds','holiday']]
from fbprophet import Prophet
m = Prophet()
m.fit(train)
train.loc[train['ds'] > '2010-11-01'].head()
future = m.make_future_dataframe(periods=52,freq='W')
preds_train = m.predict(train)
preds_test = m.predict(test)
preds_train.head()
mean_absolute_error(train['y'],preds_train['yhat'])
mean_absolute_error(test['y'],preds_test['yhat'])
m.plot_components(preds_train)<jupyter_output><empty_output><jupyter_text>Cross Val<jupyter_code>from fbprophet.diagnostics import cross_validation, performance_metrics
df_cv = cross_validation(m, horizon='500 days', initial='180 days',period='90 days')
performance_metrics(df_cv)
from fbprophet.plot import plot_cross_validation_metric
plot_cross_validation_metric(df_cv, 'mae')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1462392108508015, 'fraction_numerical': 0.01898890258939581, 'mean_word_length': 8.176470588235293, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 33, 'https://': 6, 'lorem ipsum': 0, 'www.': 1, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '337047', 'license': 'MIT', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1320, 'n_words': 264, 'path': 'module2-evaluating-forecasts/assignment.ipynb', 'repo_name': 'RidleyLeisy/DS-Unit-2-Regression-1', 'size': '4070'}