Справочник API¶
Сгенерирован из docstring'ов. Описание модулей и примеры — на отдельных страницах в разделе «Модули».
Верхний уровень¶
catboost_utils ¶
catboost_utils — UX wrapper over CatBoost.
Public API is re-exported here. Sub-modules (errors, validation, objectives,
pipeline, logging, explain, io, callbacks) are independent and can be
imported individually.
CBXClassifier ¶
CBXClassifier(
*,
auto_cat_features: bool = True,
nan_fill: NanFill = None,
early_stopping: EarlyStopping = None,
**catboost_params: Any,
)
Bases: _CBXMixin, CatBoostClassifier
CBX-enhanced CatBoostClassifier. See SPEC.md §Module 4.
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 |
CBXRegressor ¶
CBXRegressor(
*,
auto_cat_features: bool = True,
nan_fill: NanFill = None,
early_stopping: EarlyStopping = None,
**catboost_params: Any,
)
Bases: _CBXMixin, CatBoostRegressor
CBX-enhanced CatBoostRegressor. See SPEC.md §Module 4.
unwrap ¶
Reverse wrap(): restore the original CatBoost class on the instance.
validate ¶
validate(
X: DataFrame,
y: Series | None = None,
*,
cat_features: list[str | int] | None = None,
eval_set: tuple[DataFrame, Any] | None = None,
model_params: dict[str, Any] | None = None,
) -> ValidationReport
Run pre-flight checks against a training DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
feature DataFrame (a |
required |
y
|
Series | None
|
target series. Optional — when |
None
|
cat_features
|
list[str | int] | None
|
list of categorical column names or positional indices. |
None
|
eval_set
|
tuple[DataFrame, Any] | None
|
optional |
None
|
model_params
|
dict[str, Any] | None
|
optional dict of CatBoost params for cross-cutting warnings
( |
None
|
Returns:
| Type | Description |
|---|---|
ValidationReport
|
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
when |
TypeError
|
when |
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 ¶
Readable errors for CatBoost. See SPEC.md §Module 1.
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 |
unwrap ¶
Reverse wrap(): restore the original CatBoost class on the instance.
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.validation ¶
Pre-flight data validation. See SPEC.md §Module 2.
ValidationError ¶
Bases: Exception
Raised by ValidationReport.raise_if_failed() when blocking issues are present.
ValidationIssue ¶
Bases: BaseModel
Blocking problem — training will (almost certainly) fail.
ValidationReport ¶
Bases: BaseModel
Full result of validate().
ValidationWarning ¶
Bases: BaseModel
Non-blocking concern — training proceeds but the user should be aware.
validate ¶
validate(
X: DataFrame,
y: Series | None = None,
*,
cat_features: list[str | int] | None = None,
eval_set: tuple[DataFrame, Any] | None = None,
model_params: dict[str, Any] | None = None,
) -> ValidationReport
Run pre-flight checks against a training DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
feature DataFrame (a |
required |
y
|
Series | None
|
target series. Optional — when |
None
|
cat_features
|
list[str | int] | None
|
list of categorical column names or positional indices. |
None
|
eval_set
|
tuple[DataFrame, Any] | None
|
optional |
None
|
model_params
|
dict[str, Any] | None
|
optional dict of CatBoost params for cross-cutting warnings
( |
None
|
Returns:
| Type | Description |
|---|---|
ValidationReport
|
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
when |
TypeError
|
when |
catboost_utils.objectives ¶
catboost_utils.pipeline ¶
Drop-in CBXClassifier/CBXRegressor with sklearn compatibility. See SPEC.md §Module 4.
NOTE: stub — full implementation lands in a follow-up commit.
CBXClassifier ¶
CBXClassifier(
*,
auto_cat_features: bool = True,
nan_fill: NanFill = None,
early_stopping: EarlyStopping = None,
**catboost_params: Any,
)
Bases: _CBXMixin, CatBoostClassifier
CBX-enhanced CatBoostClassifier. See SPEC.md §Module 4.
CBXRegressor ¶
CBXRegressor(
*,
auto_cat_features: bool = True,
nan_fill: NanFill = None,
early_stopping: EarlyStopping = None,
**catboost_params: Any,
)
Bases: _CBXMixin, CatBoostRegressor
CBX-enhanced CatBoostRegressor. See SPEC.md §Module 4.
catboost_utils.logging ¶
Structured logging for CatBoost training output. See SPEC.md §Module 5.
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.
format_iteration_record ¶
Format a parsed record as key=value pairs (insertion order).
parse_iteration_line ¶
Try to parse one CatBoost iteration line. Returns None if not a match.
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.explain ¶
Explanation helpers: feature_importance, shap_values, check_early_stopping.
check_early_stopping ¶
Validate early-stopping configuration before fit().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
a CatBoost / CBX model instance. |
required |
eval_set
|
Any | None
|
the eval_set you intend to pass to |
None
|
Raises:
| Type | Description |
|---|---|
CBXError
|
when any early-stopping parameter is set but |
feature_importance ¶
feature_importance(
model: Any,
data: Any | None = None,
*,
type: ImportanceType = "PredictionValuesChange",
prettified: bool = True,
) -> pd.DataFrame | npt.NDArray[Any]
Return feature importances with feature names attached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
a fitted CatBoost model (or CBXClassifier/CBXRegressor). |
required |
data
|
Any | None
|
|
None
|
type
|
ImportanceType
|
CatBoost importance type. |
'PredictionValuesChange'
|
prettified
|
bool
|
when |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame | NDArray[Any]
|
DataFrame or ndarray depending on |
Raises:
| Type | Description |
|---|---|
CBXError
|
when |
shap_values ¶
Compute SHAP values and return them as a named DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
a fitted CatBoost / CBX model. |
required |
data
|
Any
|
|
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with one column per feature plus |
DataFrame
|
bias / base value) as the last column. Rows correspond to the input rows. |
Raises:
| Type | Description |
|---|---|
CBXError
|
if data is None, if the model is multiclass (not supported in v0.1), or if CatBoost reports the well-known "non-zero approx for zero-weight leaf" misconfiguration. |
catboost_utils.io ¶
Lossless save/load with metadata sidecar. See SPEC.md §Module 7.
load ¶
Load a model previously saved via save().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | PathLike[str]
|
model file path. |
required |
format
|
str
|
passed to CatBoost's |
'cbm'
|
Returns:
| Type | Description |
|---|---|
CatBoost
|
A fitted |
CatBoost
|
instance with metadata reattached when a sidecar is present. |
save ¶
Save model to path and write a metadata sidecar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
a fitted CatBoost / CBX model. |
required |
path
|
str | PathLike[str]
|
target file path. |
required |
format
|
str
|
forwarded to |
'cbm'
|
catboost_utils.callbacks ¶
Safe callback wrapper. See SPEC.md §Module 8.