featuretools.primitives.RollingMean#

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

计算给定窗口内数值的均值.

Description:

给定一个数值列表和对应的日期时间列表,返回数值的滚动均值, 从当前行开始,向前回溯指定的时间窗口(通过 window_lengthgap 指定).

输入的日期时间应为单调递增.

Parameters:
  • window_length (int, string, 可选) – 指定每个窗口中包含的数据量. 如果提供整数,它将对应于行数.对于具有均匀采样频率的数据, 例如每天一次,`window_length` 将对应于一个时间段,在这种情况下, 7 天的 window_length 为 7. 如果提供字符串,它必须是 pandas 的偏移别名字符串(’1D’, ‘1H’ 等), 它将指示每个窗口应跨越的时间长度. 可用的偏移别名列表可以在以下网址找到: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases. 默认为 3.

  • gap (int, string, 可选) – 指定在每个实例之前,窗口开始使用数据之前的回溯间隔. 如果提供整数,它将对应于行数. 如果提供字符串,它必须是 pandas 的偏移别名字符串(’1D’, ‘1H’ 等), 它将指示目标实例与其窗口开始之间的时间长度. 默认为 1.

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

注意:

只有具有固定频率的偏移别名才能用于定义 gapwindow_length. 这意味着不能使用 MW 等别名,因为它们可以表示不同的天数. (’M’ 因为不同的月份有不同的天数; ‘W’ 因为周将指示一周中的某一天,如 W-Wed,因此将 根据锚定日期指示不同的天数.)

注意:

当使用偏移别名定义 gap 时,也必须使用偏移别名定义 window_length. 当使用偏移别名定义 window_length 时,此限制不存在.实际上, 如果数据具有均匀的采样频率,使用数值 gap 更可取,因为它更高效.

Examples

>>> 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]#

Methods

__init__([window_length, gap, min_periods])

flatten_nested_input_types(input_types)

将嵌套的列模式输入展平成一个列表.

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()

Attributes

base_of

base_of_exclude

commutative

default_value

Default value this feature returns if no data found.

description_template

input_types

woodwork.ColumnSchema types of inputs

max_stack_depth

name

Name of the primitive

number_output_features

Number of columns in feature matrix associated with this feature

return_type

ColumnSchema type of return

stack_on

stack_on_exclude

stack_on_self

uses_calc_time

uses_full_dataframe