featuretools.primitives.RollingTrend#

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

计算给定时间窗口内某一列数据的趋势.

Description:

给定一个数值列表和对应的日期时间列表,返回一个滚动斜率,表示数值的线性趋势, 从当前行向前推 gap 行开始,并在指定的时间窗口(由 window_lengthgap 确定)内向后查看.

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

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.

Examples

>>> import pandas as pd
>>> rolling_trend = RollingTrend()
>>> times = pd.date_range(start="2019-01-01", freq="1D", periods=10)
>>> rolling_trend(times, [1, 2, 4, 8, 16, 24, 48, 96, 192, 384]).tolist()
[nan, nan, nan, 1.4999999999999998, 2.9999999999999996, 5.999999999999999, 7.999999999999999, 16.0, 36.0, 72.0]

我们也可以控制滚动计算前的间隔.

>>> rolling_trend = RollingTrend(gap=0)
>>> rolling_trend(times, [1, 2, 4, 8, 16, 24, 48, 96, 192, 384]).tolist()
[nan, nan, 1.4999999999999998, 2.9999999999999996, 5.999999999999999, 7.999999999999999, 16.0, 36.0, 72.0, 144.0]

我们也可以控制滚动计算所需的最小周期数.

>>> rolling_trend = RollingTrend(window_length=4, min_periods=4, gap=0)
>>> rolling_trend(times, [1, 2, 4, 8, 16, 24, 48, 96, 192, 384]).tolist()
[nan, nan, nan, 2.299999999999999, 4.599999999999998, 6.799999999999996, 12.799999999999992, 26.399999999999984, 55.19999999999997, 110.39999999999993]

我们也可以使用偏移别名字符串设置 window_lengthgap.

>>> rolling_trend = RollingTrend(window_length="4D", gap="1D")
>>> rolling_trend(times, [1, 2, 4, 8, 16, 24, 48, 96, 192, 384]).tolist()
[nan, nan, nan, 1.4999999999999998, 2.299999999999999, 4.599999999999998, 6.799999999999996, 12.799999999999992, 26.399999999999984, 55.19999999999997]
__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