我正在尝试创建一个自定义的损失函数以在 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')