Логи обучения¶
Перенаправляет вывод CatBoost во время обучения в стандартный модуль logging с разобранными полями.
import logging
from catboost_utils.logging import setup_logging, attach
setup_logging(level=logging.INFO, structured=False)
attach(model)
model.fit(X, y)
# INFO catboost_utils.training - iteration=10 learn_loss=0.423 test_loss=0.451 best_iter=8 total_ms=123 remaining_s=12.3
При structured=True каждая запись выводится как JSON-объект. К каждой разобранной строке прикрепляется словарь cbx_iteration с разобранными полями — его можно использовать в своих обработчиках логов.
attach подменяет метод model.fit, чтобы передать в CatBoost параметры log_cout и log_cerr (это параметры fit, а не конструктора). Если у модели уже задан verbose или logging_level, attach не делает ничего и пишет об этом предупреждение, чтобы не было двойного вывода.
catboost_utils.logging.handler.setup_logging ¶
setup_logging(
level: int = stdlib_logging.INFO,
*,
structured: bool = False,
stream: TextIO | None = None,
) -> stdlib_logging.Logger
Configure the catboost_utils.training logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
int
|
standard |
INFO
|
structured
|
bool
|
when |
False
|
stream
|
TextIO | None
|
where to send output (defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Logger
|
The configured logger. Idempotent — calling twice replaces the existing handler. |
catboost_utils.logging.handler.attach ¶
Attach a logging-backed stream to model for subsequent fit() calls.
log_cout / log_cerr are fit-time parameters in CatBoost (not init params);
we monkey-patch the bound fit method to inject them. Idempotent: a second
attach() call replaces the previous streams.
Skips (with a warning) when the user already set verbose / logging_level
to avoid duplicating output to stdout.
catboost_utils.logging.parser.parse_iteration_line ¶
Try to parse one CatBoost iteration line. Returns None if not a match.