百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
返回工具页/返回 Issues 列表
#2301·catboost

示例代码中的 IndexError

作者: DenisKOMAROV创建于 2023年2月18日更新于 2026年9月20日
标签python

import numpy as np from catboost import CatBoost, Pool

read the dataset

train_data = np.random.randint(0, 100, size=(100, 10)) train_labels = np.random.randint(0, 2, size=(100)) test_data = np.random.randint(0, 100, size=(50, 10))

specify training parameters via map

param = {'iterations': 5} model = CatBoost(param)

train the model

model.fit(train_pool)

make the prediction using the resulting model

preds_class = model.predict(test_pool, prediction_type='Class') preds_proba = model.predict(test_pool, prediction_type='Probability') preds_raw_vals = model.predict(test_pool, prediction_type='RawFormulaVal') print("Class", preds_class) print("Proba", preds_proba) print("Raw", preds_raw_vals)

Learning rate set to 0.5

0: learn: 0.4559230 total: 840us remaining: 3.36ms 1: learn: 0.4196856 total: 1.36ms remaining: 2.04ms 2: learn: 0.3896530 total: 1.91ms remaining: 1.27ms 3: learn: 0.3534939 total: 2.43ms remaining: 607us 4: learn: 0.3390579 total: 2.9ms remaining: 0us

IndexError Traceback (most recent call last) File ~/PROJECTS/Python/sandbox/app/boosting/catboost/catboost_demo_regressor.py:27 25 model.fit(train_pool) 26 # make the prediction using the resulting model ---> 27 preds_class = model.predict(test_pool, prediction_type='Class') 28 preds_proba = model.predict(test_pool, prediction_type='Probability') 29 preds_raw_vals = model.predict(test_pool, prediction_type='RawFormulaVal')

File ~/PROJECTS/Python/sandbox/venv/lib/python3.9/site-packages/catboost/core.py:2596, in CatBoost.predict(self, data, prediction_type, ntree_start, ntree_end, thread_count, verbose, task_type) 2547 def predict(self, data, prediction_type='RawFormulaVal', ntree_start=0, ntree_end=0, thread_count=-1, verbose=None, task_type="CPU"): 2548 """ 2549 Predict with data. 2550 (...) 2594 with probability for every class for each object. 2595 """ -> 2596 return self._predict(data, prediction_type, ntree_start, ntree_end, thread_count, verbose, 'predict', task_type)

内容来源: catboost/catboost

查看 GitHub 原文在 GitHub 查看讨论