boosters.GBLinearModel#
- class boosters.GBLinearModel#
Bases:
objectGradient Boosted Linear model.
GBLinear uses gradient boosting to train a linear model via coordinate descent. Simpler than GBDT but can be effective for linear relationships.
- coef_#
Model coefficients after fitting.
- intercept_#
Model intercept after fitting.
- is_fitted#
Whether the model has been trained.
- n_features_in_#
Number of features seen during fit.
Examples
>>> config = GBLinearConfig(n_estimators=50, learning_rate=0.3) >>> model = GBLinearModel(config=config).fit(train) >>> predictions = model.predict(X_test)
- coef_#
Model coefficients (weights).
- Returns:
Array with shape (n_features,) for single-output models or (n_features, n_outputs) for multi-output models.
- 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 GBLinearModel 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 GBLinearModel instance.
- Raises:
ValueError – If JSON is invalid.
- intercept_#
Model intercept (bias).
- Returns:
Array of shape (n_outputs,).
- n_features_in_#
Number of features the model was trained on.
- predict(data, n_threads=0)#
Make predictions on features.
Returns transformed predictions (e.g., probabilities for classification). Output shape is (n_samples, n_outputs) - sklearn convention.
- Parameters:
data – Dataset containing features.
n_threads – Number of threads (unused, for API consistency).
- Returns:
Predictions array with shape (n_samples, n_outputs).
- predict_raw(data, n_threads=0)#
Make raw (untransformed) predictions on features.
Returns raw margin scores without transformation. Output shape is (n_samples, n_outputs) - sklearn convention.
- Parameters:
data – Dataset containing features.
n_threads – Number of threads (unused, for API consistency).
- Returns:
Raw scores array with shape (n_samples, 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 GBLinear model.
This matches the Rust API style: training is a class-level constructor.
- Parameters:
train – Training dataset containing features and labels.
config – Optional GBLinearConfig. 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 GBLinearModel.