catboost / catboost/catboost

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

Open
#2,746 1 comment 0 reactions 0 assignees View on GitHub
visualization
Dominant language
C++
Stars
9.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/catboost/catboost/blob/v1.2.5/catboost/python-package/catboost/core.py#L7117).

Based on my understanding, [the offending line 7124](https://github.com/catboost/catboost/blob/v1.2.5/catboost/python-package/catboost/core.py#L7124) should look like this:

```python
{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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.