<jupyter_start><jupyter_text>Construct the signal Just for showing how the forecasting works, we invent our own signal here, that we want to forecast later.It is a mixture of random noise and some sinus graph with a positive and negative slope.<jupyter_code>x_up = np.arange(100)*0.1 + np.sin(30*np.pi*np.linspace(0, 1, 100)) + np.random.normal(scale=0.7,size=100)
x_down = np.arange(100, 0, -1)*0.15 + np.sin(30*np.pi*np.linspace(0, 1, 100)) + np.random.normal(scale=0.7,size=100)
x = np.concatenate([x_up, x_down])
x = pd.Series(data=x, index=pd.date_range('1/1/2011', periods=len(x), freq='H'))
x.head()
plt.figure(figsize=(15, 6))
plt.plot(x)
plt.show()<jupyter_output><empty_output><jupyter_text>So, we have a time series and want to construct a time series model that is able to predict the next data points.To do that, we have to construct a feature matrix by calculating the features for sub time series (see the forecasting section in the tsfresh documentation).<jupyter_code>%load_ext autoreload
%autoreload 2
df = pd.DataFrame(x)
df.reset_index(inplace=True)
df.columns = ["time", "value"]
df["kind"] = "a"
df["id"] = 1
df.head()
len(df)
from tsfresh.utilities.dataframe_functions import roll_time_series
df_shift, y = make_forecasting_frame(x, kind="price", max_timeshift=10, rolling_direction=1)<jupyter_output><empty_output><jupyter_text>`df_shift` is ready to be passed into the feature extraction process in tsfresh<jupyter_code>X = extract_features(df_shift, column_id="id", column_sort="time", column_value="value", impute_function=impute, 
                     show_warnings=False)
X.head()<jupyter_output><empty_output><jupyter_text>Here, the first row for `id=2011-01-01 01:00:00` contains features that were just calculate on `2011-01-01 00:00:00`. The third row `2011-01-01 03:00:00` contains features that were calculated on `2011-01-01 00:00:00`, `2011-01-01 01:00:00` and `2011-01-01 02:00:00`.However, because we set `max_timeshift` to 10, the features will only be based on a maximum number of 10 historic data points.We are now using the features, to train a normal AdaBoostRegressor to predict the next time step. So for every data point, we fit the model on all older data points, then predict the next data point. Then we fit it on all data points again plus that predicted data point and so on.<jupyter_code>ada = AdaBoostRegressor()

y_pred = [0] * len(y)
y_pred[0] = y.iloc[0]

for i in range(1, len(y)):
    ada.fit(X.iloc[:i], y[:i])
    y_pred[i] = ada.predict(X.iloc[i, :].values.reshape((1, -1)))
    
y_pred = pd.Series(data=y_pred, index=y.index)
y_pred = pd.Series(data=y_pred, index=y.index)
plt.figure(figsize=(15, 6))
plt.plot(y, label="true")
plt.plot(y_pred, label="predicted")
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1317020510975171, 'fraction_numerical': 0.053256567110471394, 'mean_word_length': 5.57210401891253, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '441634', 'license': 'MIT', 'n_tokens_mistral': 1094, 'n_tokens_neox': 983, 'n_words': 293, 'path': 'notebooks/timeseries_forecasting_basic_example.ipynb', 'repo_name': 'cjen07/tsfresh', 'size': '2779'}