【问题标题】:How do you define a custom primitive with parameters using the Featuretools package?如何使用 Featuretools 包定义带有参数的自定义原语?
【发布时间】:2019-11-13 22:16:45
【问题描述】:

我正在尝试使用 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() 函数来实现它?

【问题讨论】:

    标签: featuretools


    【解决方案1】:

    考虑类中的__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)
    

    调用它:log_base_n = Log(n=2)

    在 DFS 中,您可以将相应的类实例添加到原语列表中。

    【讨论】:

      猜你喜欢
      • 2018-11-11
      • 1970-01-01
      • 2019-11-19
      • 1970-01-01
      • 1970-01-01
      • 2021-07-08
      • 2021-05-24
      • 2013-07-21
      • 1970-01-01
      相关资源
      最近更新 更多