Create Custom Loss Function in Catboost

1.1k Views Asked by At

I´m trying to create a customized loss function to use in Catboost. This is the function that I'm trying to implement:

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

And this is the error I get when I train the model

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

This is the model that I am trying to train

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

0

There are 0 best solutions below