featuretools.primitives.RollingMax#
- class featuretools.primitives.RollingMax(window_length=3, gap=1, min_periods=1)[source]#
确定给定窗口内条目的最大值.
- 描述:
给定一个数字列表和相应的日期时间列表,返回数值的滚动最大值,从当前行开始,向前移动 gap 行,并在指定的窗口(由 window_length 和 gap 定义)内向后查看.
输入的日期时间应为单调递增.
- Parameters:
window_length (int, string, 可选) – 指定每个窗口中包含的数据量. 如果提供整数,它将对应于行数.对于具有均匀采样频率的数据,例如每天一次,`window_length` 将对应于一段时间,例如,`window_length` 为 7 时,对应 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.
- 注意:
仅当定义 gap 和 window_length 时,可以使用具有固定频率的偏移别名.这意味着不能使用 M 或 W 等别名,因为它们可以表示不同的天数. (’M’ 因为不同的月份有不同的天数;’W’ 因为周将指示特定的星期几,如 W-Wed,因此将根据锚定日期指示不同的天数.)
- 注意:
当使用偏移别名定义 gap 时,也必须使用偏移别名定义 window_length.当使用偏移别名定义 window_length 时,此限制不存在.实际上,如果数据具有均匀的采样频率,使用数值 gap 更高效.
Examples
>>> import pandas as pd >>> rolling_max = RollingMax(window_length=3) >>> times = pd.date_range(start='2019-01-01', freq='1min', periods=5) >>> rolling_max(times, [4, 3, 2, 1, 0]).tolist() [nan, 4.0, 4.0, 4.0, 3.0]
我们还可以控制滚动计算前的间隔.
>>> import pandas as pd >>> rolling_max = RollingMax(window_length=3, gap=0) >>> times = pd.date_range(start='2019-01-01', freq='1min', periods=5) >>> rolling_max(times, [4, 3, 2, 1, 0]).tolist() [4.0, 4.0, 4.0, 3.0, 2.0]
我们还可以控制滚动计算所需的最小周期数.
>>> import pandas as pd >>> rolling_max = RollingMax(window_length=3, min_periods=3, gap=0) >>> times = pd.date_range(start='2019-01-01', freq='1min', periods=5) >>> rolling_max(times, [4, 3, 2, 1, 0]).tolist() [nan, nan, 4.0, 3.0, 2.0]
我们还可以使用偏移别名字符串设置 window_length 和 gap.
>>> import pandas as pd >>> rolling_max = RollingMax(window_length='3min', gap='1min') >>> times = pd.date_range(start='2019-01-01', freq='1min', periods=5) >>> rolling_max(times, [4, 3, 2, 1, 0]).tolist() [nan, 4.0, 4.0, 4.0, 3.0]
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_ofbase_of_excludecommutativedefault_valueDefault value this feature returns if no data found.
description_templateinput_typeswoodwork.ColumnSchema types of inputs
max_stack_depthnameName of the primitive
number_output_featuresNumber of columns in feature matrix associated with this feature
return_typeColumnSchema type of return
stack_onstack_on_excludestack_on_selfuses_calc_timeuses_full_dataframe