RollingWindow 类

用于创建滚动窗口特征的转换类。

滚动窗口是按照 TimeSeriesDataSet 中的源时间临时定义的。 数据帧行中的源时间指示窗口的正确日期/时间边界。

如果输入数据帧不包含源时间,则将基于 max_horizon 参数对其进行创建。

示例:

data = {'store': [1] * 10 + [2] * 10 + [3] * 10,

'sales': [250, 150, 300, 200, 400, 300, 150, 200, 350, 100, 400, 300, 200, 450, 200, 350, 450, 150, 250, 500, 150, 400, 500, 300, 350, 250, 200, 400, 500, 450],

'customers': [28, 15, 30, 24, 47, 33, 15, 20, 36, 13, 38, 30, 25, 43, 20, 35, 46, 17, 28, 44, 15, 47, 50, 30, 35, 29, 25, 40, 48, 42],

'date': pd.to_datetime( ['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04', '2017-01-05', '2017-01-06', '2017-01-07', '2017-01-08', '2017-01-09', '2017-01-10'] * 3)}


>>> tsds = TimeSeriesDataSet(
data, time_series_id_column_names='store',
time_column_name='date', target_column_name='sales')
>>> window_size = 3
>>> transform_dict = {'sum': ['sales', 'customers'], 'quantile': 'sales'}
>>> window_opts = {'min_periods': 2}
>>> transform_opts = {'quantile': {'args': [0.25],
'kwargs': {'interpolation': 'lower'}}}
>>> rolling_window_transformer = RollingWindow(window_size,
transform_dict, window_opts, transform_opts)
>>> rolling_window_transformer.fit_transform(tsds).data.head(10)
                             customers  sales  customers_sum_window3
date       store origin
2017-01-01 1     2016-12-31         28    250                    nan
2017-01-02 1     2017-01-01         15    150                    nan
2017-01-03 1     2017-01-02         30    300                  43.00
2017-01-04 1     2017-01-03         24    200                  73.00
2017-01-05 1     2017-01-04         47    400                  69.00
2017-01-06 1     2017-01-05         33    300                 101.00
2017-01-07 1     2017-01-06         15    150                 104.00
2017-01-08 1     2017-01-07         20    200                  95.00
2017-01-09 1     2017-01-08         36    350                  68.00
2017-01-10 1     2017-01-09         13    100                  71.00

sales_sum_window3 sales_quantile_window3

date store origin 2017-01-01 1 2016-12-31 nan nan 2017-01-02 1 2017-01-01 nan nan 2017-01-03 1 2017-01-02 400.00 150.00 2017-01-04 1 2017-01-03 700.00 150.00 2017-01-05 1 2017-01-04 650.00 150.00 2017-01-06 1 2017-01-05 900.00 200.00 2017-01-07 1 2017-01-06 900.00 200.00 2017-01-08 1 2017-01-07 850.00 150.00 2017-01-09 1 2017-01-08 650.00 150.00 2017-01-10 1 2017-01-09 700.00 150.00

继承
RollingWindow
azureml.automl.runtime.featurizer.transformer.timeseries.forecasting_base_estimator._GrainBasedStatefulTransformer
RollingWindow

构造函数

RollingWindow(window_size: Union[int, str, pandas._libs.tslibs.offsets.DateOffset], transform_dictionary: Dict[Union[Callable[…, Optional[Any]], str], Union[str, List[str]]], window_options: Optional[Dict[str, Any]] = None, transform_options: Dict[Union[Callable[…, Optional[Any]], str], Dict[str, Any]] = {}, max_horizon: int = 1, origin_time_column_name: str = 'origin', dropna: bool = False, check_max_horizon: bool = True, backfill_cache: bool = False, freq: Optional[Union[str, pandas._libs.tslibs.offsets.DateOffset]] = None)

参数

window_size
int, <xref:pandas.tseries.offsets.DateOffset>
必需

移动窗口的大小。 每个窗口中的观察项数,或指定为 pandas.tseries.offsets.DateOffset 的时间范围。 请注意,当以 DateOffset 形式指定大小时,窗口可能包含可变数量的观察项。

transform_dictionary
dict
必需

一个字典,用于指定要应用于列的滚动窗口转换。 键是预定义的 Pandas 滚动窗口方法的函数或名称。 请参阅 https://pandas.pydata.org/pandas-docs/stable/computation.html#method-summary。 字典值是要对其应用函数的列。 每个值可以是单个列名,也可以是列名列表。

window_options
dict
默认值: None

关键字窗口选项的字典。 这些值将作为 >>**<<kwargs 传递给 pandas.Rolling 构造函数。 有关详细信息,请参阅 pandas.DataFrame.rolling。

为避免目标泄漏,将忽略此处的 center 选项设置并始终将其设置为 False。

closed 选项也将被忽略。 对于整数窗口大小,它将设置为 both。 对于 DateOffset 窗口大小,它将设置为 right。

transform_options
默认值: {}

聚合函数选项的字典。 键是聚合函数名称。 值同样是具有两个键的字典:args 和 kwargs,“args”键的值是传递给聚合函数的位置参数,“kwargs”键的值是传递给聚合函数的关键字参数。

transform_options
默认值: 1

定义要创建的源时间的整数边际。 参数可以是单个整数(指示要针对所有粒度创建的最大边际)或字典(其中键是粒度级别,每个值都是整数最大边际)。

origin_time_column_name
str
默认值: origin

输入数据帧中尚未包含源时间时要创建的源时间列的名称。 在这种情况下,转换输出的 origin_time_colunm_name 属性将设置为此参数值。 如果输入数据帧包含源时间,则忽略此参数。

dropna
bool
默认值: False

在创建滚动窗口特征时是否应删除缺失值? 默认为 False。 请注意,不会删除测试数据中的缺失值,而是使用训练数据中的值来“填充”它们。

check_max_horizon
bool
默认值: True

如果设置为 True,则将从源列计算最大边际。 将此参数设置为 False 会显著提高速度和内存消耗量。

backfill_cache
bool
默认值: False

回填 chache 来避免 NaN,以防止输出数据帧形状退化。

freq
默认值: None

方法

fit

拟合滚动窗口。

缓存训练数据的最后一个窗口。

get_col_internal_type

如果列是由滚动窗口转换器生成的,则获取该列的类型。

get_params

获取此估算器的参数。

preview_column_names

获取此转换创建的新列的列表。

此方法不会向 X 添加任何列,它只是预览转换在应用后要添加的内容。

transform

将滚动窗口转换应用于输入。

fit

拟合滚动窗口。

缓存训练数据的最后一个窗口。

fit(X: azureml.automl.runtime._time_series_data_set.TimeSeriesDataSet, y: Optional[Any] = None) -> azureml.automl.runtime.featurizer.transformer.timeseries.rolling_window.RollingWindow

参数

X
<xref:azureml.automl.runtime._time_series_data_set.TimeSeriesDataSet>
必需

训练数据的数据帧

y
必需

已忽略。 管道兼容性所必需的

返回

self

返回类型

get_col_internal_type

如果列是由滚动窗口转换器生成的,则获取该列的类型。

static get_col_internal_type(col_name: str) -> Optional[str]

参数

col_name
必需

列名称。

返回

如果列是由滚动窗口转换器生成的,则返回“window”,否则返回 None。

get_params

获取此估算器的参数。

get_params(deep=True)

参数

deep
bool, <xref:default=True>
默认值: True

如果为 True,则返回此估算器的参数和包含的子对象(即估算器)。

返回

params - 映射到其值的参数名称。

返回类型

<xref:<xref:mapping of string to any>>

preview_column_names

获取此转换创建的新列的列表。

此方法不会向 X 添加任何列,它只是预览转换在应用后要添加的内容。

preview_column_names(X: azureml.automl.runtime._time_series_data_set.TimeSeriesDataSet) -> List[str]

参数

X
<xref:azureml.automl.runtime._time_series_data_set.TimeSeriesDataSet>
必需

转换的输入数据

返回

新列名的列表

返回类型

transform

将滚动窗口转换应用于输入。

transform(X: azureml.automl.runtime._time_series_data_set.TimeSeriesDataSet) -> azureml.automl.runtime._time_series_data_set.TimeSeriesDataSet

参数

X
<xref:azureml.automl.runtime._time_series_data_set.TimeSeriesDataSet>
必需

要转换的数据帧

返回

一个新的 TimeSeriesDataSet,其中包含添加到 X 的转换结果列。

返回类型

<xref:azureml.automl.runtime._time_series_data_set.TimeSeriesDataSet>

例外

ForecastingDataException

属性

freq

返回转换的频率。

rw_option

target_column_name

transform_dict

请参阅“transform_dict”参数。

transform_opts

请参阅“transform_opts”参数。

window_opts

请参阅“window_opts”参数。

window_size

请参阅“window_size”参数。

POSTFIX_SEP

POSTFIX_SEP = '_'

RW_BY_OCCURRENCE

RW_BY_OCCURRENCE = 'rw_by_occurrence'

RW_BY_TIME

RW_BY_TIME = 'rw_by_time'

RW_POSTFIX

RW_POSTFIX = 'window'