featuretools.primitives.make_agg_primitive

featuretools.primitives.make_agg_primitive(function, input_types, return_type, name=None, stack_on_self=True, stack_on=None, stack_on_exclude=None, base_of=None, base_of_exclude=None, description=None, cls_attributes=None, uses_calc_time=False, default_value=None, commutative=False, number_output_features=1)[source]

Returns a new aggregation primitive class. The primitive infers default values by passing in empty data.

Parameters
  • function (function) – Function that takes in a series and applies some transformation to it.

  • input_types (list[ColumnSchema]) – ColumnSchema of the inputs.

  • return_type (ColumnSchema) – ColumnSchema of returned feature.

  • name (str) – Name of the function. If no name is provided, the name of function will be used.

  • stack_on_self (bool) – Whether this primitive can be in input_types of self.

  • stack_on (list[PrimitiveBase]) – Whitelist of primitives that can be input_types.

  • stack_on_exclude (list[PrimitiveBase]) – Blacklist of primitives that cannot be input_types.

  • base_of (list[PrimitiveBase) – Whitelist of primitives that can have this primitive in input_types.

  • base_of_exclude (list[PrimitiveBase]) – Blacklist of primitives that cannot have this primitive in input_types.

  • description (str) – Description of primitive.

  • cls_attributes (dict[str -> anytype]) – Custom attributes to be added to class. Key is attribute name, value is the attribute value.

  • uses_calc_time (bool) – If True, the cutoff time the feature is being calculated at will be passed to the function as the keyword argument ‘time’.

  • default_value (int, float) – Default value when creating the primitive to avoid the inference step. If no default value if provided, the inference happen.

  • commutative (bool) – If True, will only make one feature per unique set of base features.

  • number_output_features (int) – The number of output features (columns in the matrix) associated with this feature.

Example

In [1]: from featuretools.primitives import make_agg_primitive

In [2]: from woodwork.column_schema import ColumnSchema

In [3]: from woodwork.logical_types import Datetime

In [4]: def time_since_last(values, time=None):
   ...:     time_since = time - values.iloc[-1]
   ...:     return time_since.total_seconds()
   ...: 

In [5]: TimeSinceLast = make_agg_primitive(
   ...:     function=time_since_last,
   ...:     input_types=[ColumnSchema(logical_type=Datetime, semantic_tags={'time_index'})],
   ...:     return_type=ColumnSchema(semantic_tags={'numeric'}),
   ...:     description="Time since last related instance",
   ...:     uses_calc_time=True)
   ...: