gpt4 book ai didi

python - Catboost 理解 - 分类值的转换

转载 作者:行者123 更新时间:2023-11-30 09:49:56 29 4
gpt4 key购买 nike

我有一些关于 catboost 的愚蠢问题。

从catboost的文档中,我了解到行之间存在一些排列/洗牌,用于分类数据转换。( https://tech.yandex.com/catboost/doc/dg/concepts/algorithm-main-stages_cat-to-numberic-docpage/#algorithm-main-stages_cat-to-numberic )

我试图根据单个观察结果进行预测,以检查我的模型是否有效,但出现错误。然而,通过 2 个观察,它工作得很好。

我的问题是,对于 catboost 分类器的预测,由于排列,我们是否必须至少给出 2 个观察值?如果是,第一个观察结果对输出有影响吗?

最佳答案

Catboost确实有这样的限制。然而,它与排列无关,因为它们仅在拟合阶段应用。

问题在于,在 predict 以及 fit 之前应用了相同的方法 catboost.Pool._check_data_empty。对于拟合来说,不止一次观察确实至关重要。

现在检查函数需要 sum(x.shape)>2,这确实很奇怪。下面的代码说明了这个问题:

import catboost
import numpy as np
x_train3 = np.array([[1,2,3,], [2,3,4], [3,4,5]])
x_train1 = np.array([[1], [2], [3]])
y_train = np.array([1,2,3])
x_test3_2 = np.array([[4,5,6], [5,6,7]])
x_test3_1 = np.array([[4,5,6,]])
x_test1_2 = np.array([[4], [5]])
x_test1_1 = np.array([[4]])
model3 = catboost.CatBoostRegressor().fit(x_train3, y_train)
model1 = catboost.CatBoostRegressor().fit(x_train1, y_train)
print(model3.predict(x_test3_2)) # OK
print(model3.predict(x_test3_1)) # OK
print(model1.predict(x_test1_2)) # OK
print(model1.predict(x_test1_1)) # Throws an error!

目前,您可以通过在调用 predict 之前添加一两个假行来实现良好效果。它们不会影响原始行的输出。

关于python - Catboost 理解 - 分类值的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47039915/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com