Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logitraw objective function ignored for xgb.Booster #585

Open
GuidoBartoli opened this issue Oct 12, 2023 · 0 comments
Open

Logitraw objective function ignored for xgb.Booster #585

GuidoBartoli opened this issue Oct 12, 2023 · 0 comments

Comments

@GuidoBartoli
Copy link

GuidoBartoli commented Oct 12, 2023

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

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

No branches or pull requests

1 participant