【问题标题】:What is Pool in Catboost?When to use Pool instead of numpy array?Catboost 中的 Pool 是什么?何时使用 Pool 而不是 numpy 数组?
【发布时间】:2021-04-26 13:07:21
【问题描述】:

我使用这段代码来测试 CatBoostClassifier。

import numpy as np
from catboost import CatBoostClassifier, Pool

# initialize data
train_data = np.random.randint(0, 100, size=(100, 10))
train_labels = np.random.randint(0, 2, size=(100))
test_data = Pool(train_data, train_labels) #What is Pool?When to use Pool?
# test_data = np.random.randint(0,100, size=(20, 10)) #Usually we will use numpy array,will not use Pool

model = CatBoostClassifier(iterations=2,
                           depth=2,
                           learning_rate=1,
                           loss_function='Logloss',
                           verbose=True)
# train the model
model.fit(train_data, train_labels)
# make the prediction using the resulting model
preds_class = model.predict(test_data)
preds_proba = model.predict_proba(test_data)
print("class = ", preds_class)
print("proba = ", preds_proba)

关于Pool的描述是这样的:

CatBoost 中使用的池作为训练模型的数据结构。

我认为通常我们会使用 numpy 数组,不会使用 Pool。

例如我们使用:

test_data = np.random.randint(0,100, size=(20, 10))

我没有发现Pool的更多用法,所以我想知道我们什么时候会使用Pool而不是numpy数组?

【问题讨论】:

    标签: python scikit-learn catboost


    【解决方案1】:

    我对池的理解是,它只是一个方便的包装器,结合了特征、标签和进一步的元数据,如分类特征或基线。
    虽然如果您首先构建池然后使用池拟合模型并没有太大区别,但在保存训练数据方面会有所不同。如果您单独保存所有信息,它可能会不同步,或者您可能会忘记某些内容,并且在加载时需要几行来加载所有内容。游泳池在这里非常方便。
    请注意,在拟合时,您还可以将评估数据集指定为池。如果您想尝试多个评估数据集,将它们封装在一个对象中非常方便 - 这就是池的用途。

    【讨论】:

      【解决方案2】:

      关于 catboost 最重要的一点是,我们不需要对数据集中的分类特征进行编码。 catBoost 内置了一个热编码器超参数,只有在指定 cat_features 超参数时才能使用。现在 cat_features 超参数很难定义,因为一旦我们指定一个数组就会弹出错误。使用 Pool 可以简化定义。

      【讨论】:

        【解决方案3】:

        Catboost 仅适用于池,这是一种内部数据格式。如果您将 numpy 数组传递给它,它会先隐式将其转换为 Pool,而不告诉您。 如果您需要对一个数据集应用多个公式,则使用 Pool 可以显着提高性能(例如 10 倍),因为您每次都会省略转换步骤。

        【讨论】:

          猜你喜欢
          • 2018-01-25
          • 2013-04-03
          • 2018-09-06
          • 1970-01-01
          • 2020-01-28
          • 2015-04-09
          • 1970-01-01
          • 1970-01-01
          • 2012-09-20
          相关资源
          最近更新 更多