Ошибки¶
Модуль catboost_utils.errors превращает длинные ошибки CatBoost в короткое описание и подсказку, что с этим делать.
from catboost_utils import wrap, CBXError
m = wrap(CatBoostClassifier(iterations=10))
try:
m.fit(X, y) # в X есть строковая колонка, но она не указана в cat_features
except CBXError as e:
print(e.human_message)
print(e.hint)
print(e.feature_name, e.feature_idx)
Имя колонки в ошибке определяется в таком порядке (на каждом вызове fit и predict):
X.columns, если передан pandas DataFrameX.get_feature_names(), если переданcatboost.Pool- явный аргумент
feature_names= model.feature_names_после обучения- если ничего нет — показывается номер колонки
catboost_utils.errors.exceptions.CBXError ¶
CBXError(
*,
original_error: BaseException,
human_message: str,
hint: str,
feature_name: str | None = None,
feature_idx: int | None = None,
)
Bases: Exception
A CatBoost error translated into a human-readable form.
Attributes:
| Name | Type | Description |
|---|---|---|
original_error |
BaseException
|
the underlying |
human_message |
str
|
short description in plain English |
hint |
str
|
actionable advice for the user |
feature_name |
str | None
|
resolved feature name when |
feature_idx |
int | None
|
raw feature index from the original error |
catboost_utils.errors.wrapper.wrap ¶
Enhance an existing CatBoost model with readable errors and feature-name resolution.
Mutates model in place by swapping __class__; returns the same object for
chaining. isinstance(model, CatBoostClassifier) continues to work.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
T
|
a |
required |
validate
|
bool
|
reserved for future use; pre-flight validation hook. |
False
|
Returns:
| Type | Description |
|---|---|
T
|
The same |
catboost_utils.errors.wrapper.unwrap ¶
Reverse wrap(): restore the original CatBoost class on the instance.