<jupyter_start><jupyter_text>Data Exploration<jupyter_code>from setup import start_spark, extract_data

spark = start_spark(sesh_name = 'Jupyter Sktime Modelling')
train, val = extract_data(spark)
spark.stop()

train.head()<jupyter_output><empty_output><jupyter_text>MLFlow Setup<jupyter_code>import mlflow
mlflow.set_tracking_uri("http://192.168.64.21:5000/")
tracking_uri = mlflow.get_tracking_uri()
print("Current tracking uri: {}".format(tracking_uri))<jupyter_output>Current tracking uri: http://192.168.64.21:5000/<jupyter_text>The taxi_daily_forecast experiment has already been created<jupyter_code>from sktime.forecasting.model_selection import SlidingWindowSplitter
from sktime.forecasting.ets import AutoETS
from sktime.forecasting.tbats import TBATS
import numpy as np
training_window=56
forecasting_horizon=7
step_size=7
cv = SlidingWindowSplitter(fh=forecasting_horizon, window_length=training_window, step_length=step_size)
# check the split points
cv.get_cutoffs(y=train['total_rides'])
# check the number of splits
cv.get_n_splits(y=train['total_rides'])<jupyter_output><empty_output><jupyter_text>Fitting Models<jupyter_code>from sktime.forecasting.model_evaluation import evaluate
seasonality=7
forecaster = AutoETS(auto=True, sp=seasonality, n_jobs=-1)
#forecaster = TBATS(
#     use_box_cox=False,
#     use_trend=False,
#     use_damped_trend=False,
#     sp=7,
#     use_arma_errors=False,
#     n_jobs=-1)
evaluation_results = evaluate(forecaster=forecaster, y=train['total_rides'].astype('float64'), 
         cv=cv, return_data=True)
evaluation_results.columns
evaluation_results.head()<jupyter_output><empty_output><jupyter_text>tags = {"engineering": "ML Platform",        "engineering_remote": "ML Platform"} Logging To MLflow<jupyter_code>tags = {"package": "Sktime",
        "model": "sktime.forecasting.ets.AutoETS"}

# lets log all the metrics from the sktime interval
with mlflow.start_run(experiment_id=15):
    mlflow.set_tags(tags)
    mlflow.log_param("training_window", training_window)
    mlflow.log_param("forecasting_horizon", forecasting_horizon)
    mlflow.log_param("step_size", step_size)
    mlflow.log_param("seasonality", seasonality)
    
    for item in evaluation_results.iterrows():
        #print('mape: {0}'.format(item[1][0]))
        mlflow.log_metric("mape", item[1][0], step=item[0])
        
    ax = evaluation_results.test_MeanAbsolutePercentageError.hist(bins=20)
    fig = ax.get_figure()
    fig.savefig('tmp/backtest_mape_hist.png')
    mlflow.log_artifact('tmp/backtest_mape_hist.png')<jupyter_output><empty_output><jupyter_text>Evaluating the results<jupyter_code># histogram of fit loops
evaluation_results.test_MeanAbsolutePercentageError.hist(bins=20)
fig = ax.get_figure()
fig.savefig('/path/to/figure.pdf')<jupyter_output><empty_output><jupyter_text>Testing Multiple Forecasters<jupyter_code>from sktime.forecasting.compose import MultiplexForecaster
from sktime.forecasting.naive import NaiveForecaster
from sktime.forecasting.exp_smoothing import ExponentialSmoothing
from sklearn.model_selection import GridSearchCV
from sktime.forecasting.model_selection import ForecastingGridSearchCV
forecaster = MultiplexForecaster(
    forecasters=[
        ("naive", NaiveForecaster(strategy="last")),
        ("ets", ExponentialSmoothing(trend="add", sp=7)),
        ("tbats", TBATS(use_box_cox=False, use_trend=False,
                     use_damped_trend=False, sp=7,
                     use_arma_errors=False, n_jobs=-1))
    ],
)
forecaster_param_grid = {"selected_forecaster": ["ets", "naive", "tbats"]}
gscv = ForecastingGridSearchCV(forecaster, cv=cv, param_grid=forecaster_param_grid)
gscv.fit(train['total_rides'].astype('float64'))
gscv.best_params_<jupyter_output><empty_output><jupyter_text>Testing TSFresh TS Fresh needs to group windows of time together in order to generate the features that we needSo for a daily forecast leveraging tsfresh we should provide hourly or even more granular data then merge is up to daily features<jupyter_code>from sktime.transformations.panel.tsfresh import TSFreshFeatureExtractor
tsfresh_train = pd.DataFrame({'idx': [1], 'values':[train['total_rides']]})
t = TSFreshFeatureExtractor(show_warnings=False)
Xt = t.fit_transform(tsfresh_train) # train[['total_rides','total_takings']]
Xt.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11267281105990784, 'fraction_numerical': 0.012903225806451613, 'mean_word_length': 6.793536804308797, 'pattern_counts': {'":': 5, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '226143', 'license': 'MIT', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1451, 'n_words': 250, 'path': 'Forecasting_Sktime.ipynb', 'repo_name': 'Data-drone/timeseries_mlflow', 'size': '4340'}