Skip to content

save_model() Feature Importance Section can use a different importance_type #3011

Closed
@jilongliao

Description

Summary

Currently, the booster.save_model() function does not accept additional params to change the importance type when output the feature importance to the model file. The c++ layer is also hard coded to use 'split' as the importance_type as below.

std::vector<double> feature_importances = FeatureImportance(num_iteration, 0);

So it would be great to have an additional params to be able to change the behavior of feature importance, e.g. uses 'gain' as importance type.

Motivation

We uses LightGBM in our production work, and we show some diagnostic plots, such as feature importance plot, to our customers. But when they inspect the model file, they found a totally different feature importance results than our plots because we use 'gain' as importance_type, while the model file uses 'split'. So it would be great to show consistency to our customers by using the same importance type.

Description

Can we expose APIs like below:

model.booster_.save_model(path, model.booster_.best_iteration, importance_type='gain')

References

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