Skip to content

Plotting feature statistics fails on a categorical feature with too many values #2746

Description

@wxd

Problem:
Calling model.calc_feature_statistics with plot_file set to a path fails on trying to plot a categorical feature with the number of values above max_cat_features_on_plot with the following error:

Traceback (most recent call last):
  File "[...]", line 78, in main
    _stats = model.calc_feature_statistics(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.12/site-packages/catboost/core.py", line 3905, in calc_feature_statistics
    fig = _plot_feature_statistics(
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.12/site-packages/catboost/core.py", line 7146, in _plot_feature_statistics
    figs_with_names += _plot_feature_statistics_units(statistics, pool_names, feature_name, max_cat_features_on_plot)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.12/site-packages/catboost/core.py", line 7124, in _plot_feature_statistics_units
    sub_statistics = dict([(k, dict([(key, stats[key][begin : end]) for key in statistics_keys])) for k, stats in statistics])
                                                                                                      ^^^^^^^^
ValueError: too many values to unpack (expected 2)

The failing function _plot_feature_statistics_units is here.

Based on my understanding, the offending line 7124 should look like this:

{key: statistics[0][key][begin: end] for key in statistics_keys}

catboost version: 1.2.5 from Conda Forge
Operating System: Ubuntu 20.04 via Docker base image mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04
CPU: Yes
GPU: No

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions