Engineering multiple rolling features at once
Now that you've practiced some simple feature engineering, let's move on to something more complex. You'll calculate a collection of features for your time series data and visualize what they look like over time. This process resembles how many other time series models operate.
This exercise is part of the course
Machine Learning for Time Series Data in Python
Exercise instructions
- Define a list consisting of four features you will calculate: the minimum, maximum, mean, and standard deviation (in that order).
- Using the rolling window (
prices_perc_rolling
) we defined for you, calculate the features fromfeatures_to_calculate
. - Plot the results over time, along with the original time series using the given code.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define a rolling window with Pandas, excluding the right-most datapoint of the window
prices_perc_rolling = prices_perc.rolling(20, min_periods=5, closed='right')
# Define the features you'll calculate for each window
features_to_calculate = [np.min, ____, ____, ____]
# Calculate these features for your rolling window object
features = prices_perc_rolling.____(features_to_calculate)
# Plot the results
ax = features.loc[:"2011-01"].plot()
prices_perc.loc[:"2011-01"].plot(ax=ax, color='k', alpha=.2, lw=3)
ax.legend(loc=(1.01, .6))
plt.show()