featuretools.primitives.SavgolFilter#

class featuretools.primitives.SavgolFilter(window_length=None, polyorder=None, deriv=0, delta=1.0, mode='interp', cval=0.0)[source]#

Applies a Savitzky-Golay filter to a list of values.

Description:

Given a list of values, return a smoothed list which increases the signal to noise ratio without greatly distoring the signal. Uses the Savitzky–Golay filter method.

If the input list has less than 20 values, it will be returned as is.

See the following page for more info: https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.signal.savgol_filter.html

Parameters:
  • window_length (int) – The length of the filter window (i.e. the number of coefficients). window_length must be a positive odd integer.

  • polyorder (int) – The order of the polynomial used to fit the samples. polyorder must be less than window_length.

  • deriv (int) – Optional. The order of the derivative to compute. This must be a nonnegative integer. The default is 0, which means to filter the data without differentiating.

  • delta (float) – Optional. The spacing of the samples to which the filter will be applied. This is only used if deriv > 0. Default is 1.0.

  • mode (str) –

    Optional. Must be ‘mirror’, ‘constant’, ‘nearest’, ‘wrap’ or ‘interp’. This determines the type of extension to use for the padded signal to which the filter is applied. When mode is ‘constant’, the padding value is given by cval. See the Notes for more details on ‘mirror’, ‘constant’, ‘wrap’, and ‘nearest’.

    When the ‘interp’ mode is selected (the default), no extension is used. Instead, a degree polyorder polynomial is fit to the last window_length values of the edges, and this polynomial is used to evaluate the last window_length // 2 output values.

  • cval (scalar) – Optional. Value to fill past the edges of the input if mode is ‘constant’. Default is 0.0.

Examples

>>> savgol_filter = SavgolFilter()
>>> data = [0, 1, 1, 2, 3, 4, 5, 7, 8, 7, 9, 9, 12, 11, 12, 14, 15, 17, 17, 17, 20]
>>> [round(x, 4) for x in savgol_filter(data).tolist()[:3]]
[0.0429, 0.8286, 1.2571]

We can control window_length and polyorder of the filter.

>>> savgol_filter = SavgolFilter(window_length=13, polyorder=3)
>>> [round(x, 4) for x in savgol_filter(data).tolist()[:3]]
[-0.0962, 0.6484, 1.4451]

We can also control the deriv and delta parameters.

>>> savgol_filter = SavgolFilter(deriv=1, delta=1.5)
>>> [round(x, 4) for x in savgol_filter(data).tolist()[:3]]
[0.754, 0.3492, 0.2778]

Finally, we can use mode to control how edge values are handled.

>>> savgol_filter = SavgolFilter(mode='constant', cval=5)
>>> [round(x, 4) for x in savgol_filter(data).tolist()[:3]]
[1.5429, 0.2286, 1.2571]
__init__(window_length=None, polyorder=None, deriv=0, delta=1.0, mode='interp', cval=0.0)[source]#

Methods

__init__([window_length, polyorder, deriv, ...])

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

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