featuretools.primitives.AbsoluteDiff#

class featuretools.primitives.AbsoluteDiff(method='ffill', limit=None)[source]#
Calculates the absolute difference from the previous element

in a list of numbers.

Description:

The absolute difference from the previous element is computed for all elements in the input. The first item in the output will always be nan, since there is no previous element for the first element. Elements in the input containing nan will be filled using either a forward-fill or backward-fill method, specified by the method argument.

Parameters:
  • method (str) –

    Method to use for filling nan values in reindexed Series. Possible values are [‘pad’, ‘ffill’, ‘backfill’, ‘bfill’]. Default is ‘ffill’.

    pad / ffill: propagate last valid observation forward

    to fill gap

    backfill / bfill: propagate next valid observation backward

    to fill gap

  • limit (int) – The max number of consecutive NaN values in a gap that can be filled. Default is None.

Examples

>>> absolute_diff = AbsoluteDiff()
>>> absolute_diff([2, 5, 15, 3]).tolist()
[nan, 3.0, 10.0, 12.0]

Forward filling of input elements using the ‘ffill’ argument

>>> absolute_diff_ffill = AbsoluteDiff(method="ffill")
>>> absolute_diff_ffill([None, 5, 10, 20, None, 10, None]).tolist()
[nan, nan, 5.0, 10.0, 0.0, 10.0, 0.0]

Backward filling of input element using the ‘bfill’ argument

>>> absolute_diff_bfill = AbsoluteDiff(method="bfill")
>>> absolute_diff_bfill([None, 5, 10, 20, None, 10, None]).tolist()
[nan, 0.0, 5.0, 10.0, 10.0, 0.0, nan]

The number of nan values that are filled can be limited

>>> absolute_diff_limitfill = AbsoluteDiff(limit=2)
>>> absolute_diff_limitfill([2, None, None, None, 3, 1]).tolist()
[nan, 0.0, 0.0, nan, nan, 2.0]
__init__(method='ffill', limit=None)[source]#

Methods

__init__([method, limit])

flatten_nested_input_types(input_types)

Flattens nested column schema inputs into a single list.

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

compatibility

Additional compatible libraries

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

series_library

stack_on

stack_on_exclude

stack_on_self

uses_calc_time

uses_full_dataframe