0

I'm trying to create a custom transformation using the Featuretools package where I can input a parameter and change the behaviour of the the function

For example for the following custom log transformation class I wish to add a base parameter so I can do log transformations of features with different bases:

class Log(TransformPrimitive):
    """Computes the logarithm for a numeric column."""

    name = 'log'
    input_types = [Numeric]
    return_type = Numeric

    def get_function(self):
        return np.log

How would I go about implementing such a primitive and moreover how would it be implemented using the featuretools.dfs() function?

1 Answers1

0

Consider an __init__ function within the class.

For example,

class Log(TransformPrimitive):
    """Computes the logarithm for a numeric column."""

    name = 'log'
    input_types = [Numeric]
    return_type = Numeric

    def __init__(self, n=3):
        self.n = n

    def get_function(self):
        return np.log 
        # adjust for variable base, probably using something like 
        # np.log(array) / np.log(self.n)

To call it: log_base_n = Log(n=2).

In DFS you would add the corresponding class instance to the list of primitives.