如何在 google colab 中显示 catboost 图?

How to show catboost plot in google colab?

我在 google colaboratory 中使用 catboost 模块对增强分类器进行建模。 我关注了 official example:

from catboost import CatBoostClassifier, Pool

train_data = [[1, 3], [0, 4], [1, 7], [0, 3]]
train_labels = [1, 0, 1, 1]

model = CatBoostClassifier(learning_rate=0.03)

model.fit(train_data,
          train_labels,
          verbose=False,
          plot=True)

但这不会在 Google Colab 笔记本中显示任何情节。

这是我的 google colab 代码:

import sys
ENV_COLAB = 'google.colab' in sys.modules

if ENV_COLAB:

    !pip install catboost
    !pip install ipywidgets
    !jupyter nbextension enable --py widgetsnbextension

    print('Environment: Google Colab')

from catboost import CatBoostClassifier, Pool

train_data = [[1, 3], [0, 4], [1, 7], [0, 3]]
train_labels = [1, 0, 1, 1]

model = CatBoostClassifier(learning_rate=0.03)

model.fit(train_data,
          train_labels,
          verbose=False,
          plot=True)

Google colab 只是打印 <catboost.core.CatBoostClassifier at 0x7fc7a846d898> 而不是显示 catboost 官方网页中显示的情节。

Catboost 的绘图选项在 Google Colab 或 Jupiter Lab 中尚不可用。现在,'solution' 是 运行 您在常规 jupyter notebook 中的代码。

Github 上对此进行了多次讨论,catboost 团队成员已经承认了这个问题。真正的解决方案似乎是他们需要生成一个特殊的扩展以启用 Google Colab 或 Jupiter Lab 中的绘图。不幸的是,他们在 2019 年 10 月表示 "We are not working on that, we would very much appreciate any help!" https://github.com/catboost/catboost/issues/262

(另见:https://github.com/catboost/catboost/issues/1092