Skip to content

There are invalid params and some of them will be ignored. Parameter {"eval_metric":"PythonUserDefinedPerObject"} is ignored, because it cannot be parsed. #873

@StasCheb

Description

@StasCheb

Problem:There are invalid params and some of them will be ignored.
Parameter {"eval_metric":"PythonUserDefinedPerObject"} is ignored, because it cannot be parsed.
catboost version:0.15
Operating System:
CPU:

class LoglossMetric(object):
    def get_final_error(self, error, weight):
        return error / (weight + 1e-38)

    def is_max_optimal(self):
        return True

    def evaluate(self, approxes, target, weight):
        # approxes is list of indexed containers
        # (containers with only __len__ and __getitem__ defined), one container
        # per approx dimension. Each container contains floats.
        # weight is one dimensional indexed container.
        # target is float.   
        # weight parameter can be None.
        # Returns pair (error, weights sum)

        assert len(approxes) == 1
        assert len(target) == len(approxes[0])

        approx = approxes[0]
        error_sum = 0.0
        weight_sum = 0.0

        for i in xrange(len(approx)):
            w = 1.0 if weight is None else weight[i]
            
            approxExp = math.exp(approx[i])
            approxEx = approxExp / (1 + approxExp)

            weight_sum += w
            if 1==0:
                error_sum += (1-approxEx) * weight[i] * 0.10 - (weight[i]+100) * approxEx
            elif approxEx >= 0.5 and target[i] == 1:  # tp
                error_sum += 0
            elif approxEx >= 0.5 and target[i] == 0:  # fp
                error_sum -= weight[i] * 0.10
            elif approxEx < 0.5 and target[i] == 1:  # fn
                error_sum -= (weight[i] + 100)
            else:  # tn
                error_sum += weight[i] * 0.10
            
            
        print("errorSumOur:", error_sum)    
        return error_sum, weight_sum
castom_model = CatBoostClassifier(iterations=1000, learning_rate=0.5, eval_metric=LoglossMetric())

 castom_model.fit(X_train,
         y_train,
         cat_features,
         sample_weight=sample_weight,
         use_best_model=True,
         eval_set=eval_dataset)
castom_model.save_model("model")

вызов в другом файле:

class LoglossMetric(object):
                def get_final_error(self, error, weight):
                    return error / (weight + 1e-38)

                def is_max_optimal(self):
                    return True

                def evaluate(self, approxes, target, weight):
                    # approxes is list of indexed containers
                    # (containers with only __len__ and __getitem__ defined), one container
                    # per approx dimension. Each container contains floats.
                    # weight is one dimensional indexed container.
                    # target is float.   
                    # weight parameter can be None.
                    # Returns pair (error, weights sum)

                    assert len(approxes) == 1
                    assert len(target) == len(approxes[0])

                    approx = approxes[0]
                    error_sum = 0.0
                    weight_sum = 0.0
                    #print(":",len(approxes[0]))
                    for i in xrange(len(approx)):
                        w = 1.0 if weight is None else weight[i]

                        approxExp = math.exp(approx[i])
                        approxEx = approxExp / (1 + approxExp)

                        weight_sum += w
                        #error_sum += w * (target[i] * approx[i] - math.log(1 + math.exp(approx[i])))
                        if 1==0:
                            error_sum += (1-approxEx) * weight[i] * 0.10 - (weight[i] +100) * approxEx
                        elif approxEx >= 0.5 and target[i] == 1:  # tp
                            error_sum += 0
                        elif approxEx >= 0.5 and target[i] == 0:  # fp
                            error_sum -= weight[i] * 0.10
                        elif approxEx < 0.5 and target[i] == 1:  # fn
                            error_sum -= (weight[i] +100)
                        else:  # tn
                            error_sum += weight[i] * 0.10
                    print("errorSumOur:", error_sum)    
                    return error_sum, weight_sum

 from_file = CatBoostClassifier(eval_metric=LoglossMetric())
 from_file.load_model("model")

 t = from_file.predict_proba(train_data)

все работает, но консоль выдает :

There are invalid params and some of them will be ignored.
Parameter {"eval_metric":"PythonUserDefinedPerObject"} is ignored, because it cannot be parsed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions