如何使用Featuretools包使用参数定义自定义原语?

时间:2019-07-03 08:59:30

标签: featuretools

我正在尝试使用Featuretools包创建自定义转换,我可以在其中输入参数并更改函数的行为

例如,对于以下自定义日志转换类,我希望添加一个基本参数,以便可以对具有不同基准的要素进行日志转换:

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

我将如何实现这种原语,又如何使用featuretools.dfs()函数来实现?

1 个答案:

答案 0 :(得分:0)

在类中考虑一个[{'name': 'https://python-rq.org', 'children': [{'name': 'https://python-rq.org/a', 'children': [{'name': 'https://python-rq.org/a/b', 'children': []}]}, {'name': 'https://python-rq.org/c', 'children': []}]}] 函数。

例如,

__init__

要调用它: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)

在DFS中,您将相应的类实例添加到基元列表中。