开始使用免费开始使用

一次性构建多个滚动特征

既然您已经练习了一些基础的特征工程,我们来尝试更复杂的内容。您将为时间序列数据计算一组特征,并将其随时间的变化可视化。这一流程与许多时间序列模型的工作方式类似。

本练习是课程的一部分

Python 中的时间序列机器学习

查看课程

练习说明

  • 定义一个包含 4 个特征的列表,依次为:最小值、最大值、均值和标准差。
  • 使用我们为您定义的滚动窗口 (prices_perc_rolling),从 features_to_calculate 计算这些特征。
  • 使用给定代码将结果随时间绘制出来,并与原始时间序列一起展示。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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()
编辑并运行代码