#2301·catboost

IndexError in demo example code

Author: DenisKOMAROVCreated Feb 18, 2023Updated Sep 20, 2026
Labelspython

Problem: IndexError in demo example code catboost version: 1.1.1 Operating System: Ubuntu 18.04 CPU: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz GPU: none

Python: 3.9.15 IPython: 8.10.0 numpy.version = '1.24.2'

IndexError in running demo example code from:

https://catboost.ai/en/docs/concepts/python-quickstart#classification-and-regression

Full code

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))
                                
train_pool = Pool(train_data, 
                  train_labels)

test_pool = Pool(test_data) 
# 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)

Error log

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)

File ~/PROJECTS/Python/sandbox/venv/lib/python3.9/site-packages/catboost/core.py:2544, in CatBoost._predict(self, data, prediction_type, ntree_start, ntree_end, thread_count, verbose, parent_method_name, task_type)
   2541 data, data_is_single_object = self._process_predict_input_data(data, parent_method_name, thread_count)
   2542 self._validate_prediction_type(prediction_type)
-> 2544 predictions = self._base_predict(data, prediction_type, ntree_start, ntree_end, thread_count, verbose, task_type)
   2545 return predictions[0] if data_is_single_object else predictions

File ~/PROJECTS/Python/sandbox/venv/lib/python3.9/site-packages/catboost/core.py:1811, in _CatBoostBase._base_predict(self, pool, prediction_type, ntree_start, ntree_end, thread_count, verbose, task_type)
   1810 def _base_predict(self, pool, prediction_type, ntree_start, ntree_end, thread_count, verbose, task_type):
-> 1811     return self._object._base_predict(pool, prediction_type, ntree_start, ntree_end, thread_count, verbose, task_type)

File _catboost.pyx:4759, in _catboost._CatBoost._base_predict()

File _catboost.pyx:4776, in _catboost._CatBoost._base_predict()

File _catboost.pyx:1623, in _catboost.transform_predictions()

File _catboost.pyx:5587, in _catboost._convert_to_visible_labels()

IndexError: index 0 is out of bounds for axis 0 with size 0```