Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom logger on CatBoostClassifier doesn't work #2277

Closed
francescoalongi opened this issue Jan 25, 2023 · 0 comments
Closed

Custom logger on CatBoostClassifier doesn't work #2277

francescoalongi opened this issue Jan 25, 2023 · 0 comments
Assignees

Comments

@francescoalongi
Copy link

Problem:
I don't fully understand how to use the log_cout parameter of the CatBoostClassifier.fit method.
The doc says that this parameter should take as input the "Output stream or callback for logging".
I tried to pass a custom logger in order to log the training details on a specific handler, but it seems that either I am doing it wrong, or the log_cout doesn't work as it should. Here is a minimal script to reproduce the error:

import catboost
import logging


x = [[0,45,45],[4,2,6],[78,1,35]]
y = [0,1,0]

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)

logger.addHandler(handler)

logging.info("Starting training...")

model = catboost.CatBoostClassifier()
model.fit(x, y, log_cout=logger.info)

This code outputs:

Starting training...
Traceback (most recent call last):
  File "_catboost.pyx", line 5950, in _catboost._WriteLog
  File "_catboost.pyx", line 5950, in _catboost._WriteLog
  File "_catboost.pyx", line 5950, in _catboost._WriteLog
  [Previous line repeated 997 more times]
AttributeError: '_GeneratorContextManager' object has no attribute 'write'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/francesco*/Documents/sample_script.py", line 20, in <module>
    model.fit(x, y, log_cout=logging.info)
  File "/home/francesco*/miniconda3/lib/python3.9/site-packages/catboost/core.py", line 5128, in fit
    self._fit(X, y, cat_features, text_features, embedding_features, None, sample_weight, None, None, None, None, baseline, use_best_model,
  File "/home/francesco*/miniconda3/lib/python3.9/site-packages/catboost/core.py", line 2355, in _fit
    self._train(
  File "/home/francesco*/miniconda3/lib/python3.9/site-packages/catboost/core.py", line 1759, in _train
    self._object._train(train_pool, test_pool, params, allow_clear_pool, init_model._object if init_model else None)
SystemError: <method '_train' of '_catboost._CatBoost' objects> returned a result with an error set

The tests that can be found in the catboost/python-package/ut/medium/test.py file only mention the case where the log_cout implements the write() method, what about a logger?

catboost version: 1.1.1
Operating System: Ubuntu 22.04.1 LTS
CPU: 11th Gen Intel® Core™ i7-1165G7 @ 2.80GHz × 8
GPU: x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants