在Catboost中创建自定义损耗函数

2024-09-29 17:45:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个定制的损耗函数,用于Catboost。这是我试图实现的功能:

class ErrorLoss(object):
    def calc_ders_range(self, approxes, targets, weights):
        a = (approxes >= targets)   
        b = sum(a)         
        s = a.shape[0]     
        percentage = b / s   
        error=(targets - approxes)**2  
        cases=targets.shape[0]
        loss=(percentage)+((np.sqrt(sum(error)/cases))/np.mean(targets))
        return loss

这就是我训练模型时得到的错误

CatBoostError:line 11, in calc_ders_range
    a = (approxes >= targets)
TypeError: '>=' not supported between instances of '_catboost._DoubleArrayWrapper' and '_catboost._FloatArrayWrapper'

这就是我试图训练的模型

model = CatBoostRegressor(iterations=20,
                          learning_rate=0.001,
                          loss_function = ErrorLoss(), eval_metric = 'MAE')


Tags: 模型npcalcrangeerrorsumshapetargets

热门问题