Skip to content

Logitraw objective function ignored for xgb.Booster #585

Open
@GuidoBartoli

Description

When exporting a Booster model trained with the Logitraw objective function using m2cgen, a sigmoid function is applied to the final score in the resulting C or Python code as if the Logistic objective function had been utilized during training.

#include <math.h>

static float sigmoid(float x) {
    if (x < 0) {
        float z = expf(x);
        return z / (1.0f + z);
    }
    return 1.0f / (1.0f + expf(-x));
}

void predict(uint32_t* x, float* y) {
    // [... boosting rounds omitted ...]

    float v11 = sigmoid(v0 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10);
    memcpy(y, (float[]){1.0f - v11, v11}, 2 * sizeof(float));
}

In this snippet, the sigmoid() function should not be applied on the final sum, since logitraw uses the raw score output from single trees.

Anyone can confirm this?

Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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