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

Issue with Feature Importance Visualization due to Special Character Handling in Booster.getScore with Xgboost4j v1.7.5 #10090

Closed
Drincann opened this issue Mar 6, 2024 · 2 comments

Comments

@Drincann
Copy link

Drincann commented Mar 6, 2024

Hello xgboost4j Developers,

I've encountered an issue within the xgboost4j library related to generating feature importance visualization when the feature map contains special characters such as [, ], <, >, etc. This problem specifically arises in the context of the Booster.getScore method.

Environment

xgboost4j version: 1.7.5

JDK: Azul Zulu 11.0.19

Description of the Issue

While generating a feature map for visualization purposes, certain feature names containing special characters ([, ]) lead to an ArrayIndexOutOfBoundsException when calling booster.getScore(featureMapPath, "cover"). It appears that the serialization and deserialization process within Booster.getScore does not properly handle these characters, resulting in an illegal state of the serialized model structure.

For example, a feature map entry like:

...
417 【Onehot】endpoint-[GET]/api/example q
...

triggers the exception:

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1

    at ml.dmlc.xgboost4j.java.Booster.getFeatureImportanceFromModel(Booster.java:601)
    at ml.dmlc.xgboost4j.java.Booster.getScore(Booster.java:560)

Investigation

It was found that the issue is due to the lack of escaping for special characters in the feature names when applied to the model's serialized form. The unescaped ] character in the model's serialized form causes the model structure to be parsed incorrectly, leading to failure in generating feature importance statistics.

As a temporary workaround, I implemented a method to strip these special characters from feature names before generating visualization data:

private String escape(String name) {
    return name.replaceAll("[\\[\\]<>\n,]|gain=|cover=", "");
}

Questions

Is there an existing implementation for escaping special characters in feature names that I might have overlooked?
If not, would you consider adding support for handling special characters in feature names to prevent serialization/deserialization issues?

I greatly appreciate your time and efforts in maintaining and enhancing the xgboost4j library. Your guidance or updates on this matter would be highly valued and beneficial to many users facing similar issues.

Thank you very much for your support and for the incredible work you do with xgboost4j.

@Drincann Drincann changed the title Issue with Feature Importance Visualization due to Special Character Handling in Booster.getScore Issue with Feature Importance Visualization due to Special Character Handling in Booster.getScore with Xgboost4j v1.7.5 Mar 6, 2024
@trivialfis
Copy link
Member

I think this was fixed by #9923, but we haven't got an ETA for a new release yet.

@trivialfis
Copy link
Member

Closing it now since it's fixed in the lastest. Feel free to use nightly before the new release.

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

No branches or pull requests

2 participants