featuretools.primitives.RollingMean#

class featuretools.primitives.RollingMean(window_length=3, gap=1, min_periods=0)[source]#

计算给定窗口内条目的平均值。

说明

给定一个数字列表和相应的日期时间列表,返回一个滚动平均值。该计算从距当前行向前数 gap 行的位置开始,并向后回溯由 window_lengthgap 定义的指定时间窗口内的数据。

输入日期时间应是单调的。

参数:
  • window_length (int, string, optional) – 指定每个窗口包含的数据量。如果提供整数,则对应于行数。对于采样频率均匀的数据,例如每天采样一次,window_length 为 7 将对应于一个为期 7 天的时间段。如果提供字符串,则必须是 pandas 的偏移别名字符串之一(例如 ‘1D’、‘1H’ 等),它将指示每个窗口应跨越的时间长度。可用的偏移别名列表可在 https://pandas.ac.cn/pandas-docs/stable/user_guide/timeseries.html#offset-aliases 找到。默认为 3。

  • gap (int, string, optional) – 指定从每个实例向后计算的间隔,在此间隔之后才开始可用数据的窗口。如果提供整数,则对应于行数。如果提供字符串,则必须是 pandas 的偏移别名字符串之一(例如 ‘1D’、‘1H’ 等),它将指示目标实例与其窗口开始之间的时间长度。默认为 1。

  • min_periods (int, optional) – 执行窗口计算所需的最小观测次数。当 window_length 是整数时,min_periods 不能大于 window_length。当 window_length 是偏移别名字符串时,不存在此限制,但应注意不要选择一个 min_periods,使其总是大于窗口中的观测次数。默认为 1。

注意

定义 gap 和 window_length 时,只能使用具有固定频率的偏移别名。这意味着不能使用诸如 MW 等别名,因为它们可以表示不同的天数。(‘M’,因为不同月份的天数不同;‘W’,因为周可以表示一周中的某一天,例如 W-Wed,因此根据锚定日期,表示的天数也会不同。)

注意

使用偏移别名定义 gap 时,也必须使用偏移别名来定义 window_length。仅使用偏移别名定义 window_length 时不存在此限制。实际上,如果数据具有均匀的采样频率,则更推荐使用数字类型的 gap,因为它更高效。

示例

>>> import pandas as pd
>>> rolling_mean = RollingMean(window_length=3)
>>> times = pd.date_range(start='2019-01-01', freq='1min', periods=5)
>>> rolling_mean(times, [4, 3, 2, 1, 0]).tolist()
[nan, 4.0, 3.5, 3.0, 2.0]

我们还可以控制滚动计算前的间隔。

>>> import pandas as pd
>>> rolling_mean = RollingMean(window_length=3, gap=0)
>>> times = pd.date_range(start='2019-01-01', freq='1min', periods=5)
>>> rolling_mean(times, [4, 3, 2, 1, 0]).tolist()
[4.0, 3.5, 3.0, 2.0, 1.0]

我们还可以控制滚动计算所需的最小观测次数。

>>> import pandas as pd
>>> rolling_mean = RollingMean(window_length=3, min_periods=3, gap=0)
>>> times = pd.date_range(start='2019-01-01', freq='1min', periods=5)
>>> rolling_mean(times, [4, 3, 2, 1, 0]).tolist()
[nan, nan, 3.0, 2.0, 1.0]
__init__(window_length=3, gap=1, min_periods=0)[source]#

方法

__init__([window_length, gap, min_periods])

flatten_nested_input_types(input_types)

将嵌套的列 schema 输入展平为单个列表。

generate_name(base_feature_names)

generate_names(base_feature_names)

get_args_string()

get_arguments()

get_description(input_column_descriptions[, ...])

get_filepath(filename)

get_function()

属性

base_of

base_of_exclude

commutative

default_value

如果未找到数据,此特征返回的默认值。

description_template

input_types

输入的 woodwork.ColumnSchema 类型

max_stack_depth

name

原语的名称

number_output_features

与此特征关联的特征矩阵中的列数

return_type

返回值的 ColumnSchema 类型

stack_on

stack_on_exclude

stack_on_self

uses_calc_time

uses_full_dataframe