我对 catboost 有一些简单的问题。
从 catboost 的文档中,我了解到在分类数据转换时,数据行之间会有一些排列/洗牌操作。(https://tech.yandex.com/catboost/doc/dg/concepts/algorithm-main-stages_cat-to-numberic-docpage/#algorithm-main-stages_cat-to-numberic)
我尝试预测单个观测值以检查我的模型是否工作,但得到了一个错误。然而,使用两个观测值时,它运行得很好。
我的问题是,对于 catboost 分类器的预测,我们是否必须至少提供两个观测值,因为排列的原因?如果是的话,第一个观测值是否会影响输出?
回答:
Catboost 确实有这样的限制。然而,这与排列无关,因为排列只在拟合阶段应用。
问题在于在 predict
和 fit
之前都应用了相同的 catboost.Pool._check_data_empty
方法。对于拟合来说,拥有多个观测值确实至关重要。
现在检查函数要求 sum(x.shape)>2
,这确实很奇怪。以下代码说明了这个问题:
import catboostimport numpy as npx_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)) # OKprint(model3.predict(x_test3_1)) # OKprint(model1.predict(x_test1_2)) # OKprint(model1.predict(x_test1_1)) # Throws an error!
目前,你可以在调用 predict
之前添加一到两行假数据。这样做不会影响原始行的输出。