boosters.GBDTModel#

class boosters.GBDTModel#

Bases: object

Gradient Boosted Decision Tree model.

This is the main model class for training and prediction with gradient boosted decision trees.

is_fitted#

Whether the model has been fitted.

n_trees#

Number of trees in the fitted model.

n_features#

Number of features the model was trained on.

config#

Model configuration.

Examples

>>> from boosters import GBDTModel, Dataset
>>> train = Dataset(X, y)
>>> model = GBDTModel().fit(train)
>>> predictions = model.predict(train)
feature_importance(importance_type=Ellipsis)#

Get feature importance scores.

Parameters:

importance_type – Type of importance (ImportanceType.Split or ImportanceType.Gain).

Returns:

Array of importance scores, one per feature.

feature_names#

Feature names from training dataset (if provided).

static from_bytes(data)#

Load model from binary bytes.

Parameters:

data – Binary bytes in .bstr format.

Returns:

Loaded GBDTModel instance.

Raises:

ValueError – If bytes are invalid or corrupted.

static from_json_bytes(data)#

Load model from JSON bytes.

Parameters:

data – UTF-8 JSON bytes in .bstr.json format.

Returns:

Loaded GBDTModel instance.

Raises:

ValueError – If JSON is invalid.

n_features#

Number of features the model was trained on.

n_trees#

Number of trees in the fitted model.

predict(data, n_threads=0)#

Make predictions on data.

Returns transformed predictions (e.g., probabilities for classification). Output shape is (n_samples, n_outputs) - sklearn convention.

Parameters:
  • data – Dataset containing features for prediction.

  • n_threads – Number of threads for parallel prediction (0 = auto).

Returns:

Predictions array with shape (n_samples, n_outputs).

predict_raw(data, n_threads=0)#

Make raw (untransformed) predictions on data.

Returns raw margin scores without transformation. Output shape is (n_samples, n_outputs) - sklearn convention.

Parameters:
  • data – Dataset containing features for prediction.

  • n_threads – Number of threads for parallel prediction (0 = auto).

Returns:

Raw scores array with shape (n_samples, n_outputs).

shap_values(data)#

Compute SHAP values for feature contribution analysis.

Parameters:

data – Dataset containing features for SHAP computation.

Returns:

Array with shape (n_samples, n_features + 1, n_outputs).

to_bytes()#

Serialize model to binary bytes.

Returns:

Binary representation of the model (.bstr format).

Raises:

RuntimeError – If model is not fitted or serialization fails.

to_json_bytes()#

Serialize model to JSON bytes.

Returns:

UTF-8 JSON representation of the model (.bstr.json format).

Raises:

RuntimeError – If model is not fitted or serialization fails.

static train(train, config=None, val_set=None, n_threads=0)#

Train a new GBDT model.

This matches the Rust API style: training is a class-level constructor.

Parameters:
  • train – Training dataset containing features and labels.

  • config – Optional GBDTConfig. If not provided, uses default config.

  • val_set – Optional validation dataset for early stopping and evaluation.

  • n_threads – Number of threads for parallel training (0 = auto).

Returns:

Trained GBDTModel.