featuretools.primitives.make_trans_primitive

featuretools.primitives.make_trans_primitive(function, input_types, return_type, name=None, description=None, cls_attributes=None, uses_calc_time=False, commutative=False, number_output_features=1)

Returns a new transform primitive class

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

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

  • return_type (Variable) – Variable type of return.

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

  • 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’.

  • 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_trans_primitive

In [2]: from featuretools.variable_types import Variable, Boolean

In [3]: def pd_is_in(array, list_of_outputs=None):
   ...:     if list_of_outputs is None:
   ...:         list_of_outputs = []
   ...:     return pd.Series(array).isin(list_of_outputs)
   ...: 

In [4]: def isin_generate_name(self):
   ...:     return u"%s.isin(%s)" % (self.base_features[0].get_name(),
   ...:                              str(self.kwargs['list_of_outputs']))
   ...: 

In [5]: IsIn = make_trans_primitive(
   ...:     function=pd_is_in,
   ...:     input_types=[Variable],
   ...:     return_type=Boolean,
   ...:     name="is_in",
   ...:     description="For each value of the base feature, checks "
   ...:     "whether it is in a list that provided.",
   ...:     cls_attributes={"generate_name": isin_generate_name})
   ...: