【问题标题】:Ho to make a prediction for a single sample with CatBoost?如何使用 CatBoost 对单个样本进行预测?
【发布时间】:2019-12-04 21:46:29
【问题描述】:

所以我用一些包含一些分类变量的数据训练了一个 CatBoost 分类器模型;问题是我想对单个样本进行预测,但总是出错;像这样:

# X is a dataframe with 23 vars, 14 of which are categorical
model.predict(X.loc[1])  # This gives the error below

CatBoostError: Invalid cat_features[1] = 1 value: index must be < 1.


# I've tried reshaping the series but this raises another error
model.predict(X.loc[1].values.reshape(1, -1)) # This form works with LightGBM

CatBoostError: 'data' is numpy array of floating point numerical type, it means no categorical 
features, but 'cat_features' parameter specifies nonzero number of categorical features

但是,如果我尝试使用两个或更多样本,它会完美运行

model.predict(X.iloc[:2,:]) 

array([1., 0])

我不明白如何只做一个简单的预测,我还没有找到这方面的信息。

¿如何使用 catboost 对单个样本进行预测?

【问题讨论】:

    标签: python prediction catboost


    【解决方案1】:

    sklearn API 就是这样工作的。您需要将集合传递给predict 方法。只需将您的样本包装在一个列表中即可。

    model.predict([X.loc[1]])
    

    【讨论】:

      猜你喜欢
      • 2019-11-05
      • 2021-07-07
      • 1970-01-01
      • 2019-11-29
      • 2013-09-08
      • 2022-11-05
      • 2018-09-08
      • 2021-04-27
      • 2018-02-02
      相关资源
      最近更新 更多