Skip to main content

cwgboost

tests

Component-wise gradient boosting for additive regression models, with P-splines and regression stumps as base learners.

The model it fits is an additive model

f(x) = intercept + f_1(x_1) + f_2(x_2) + ... + f_p(x_p),

built up step by step. In every boosting step a base learner is fitted to the current residuals on each feature separately, and only the one that reduces the loss most is added (scaled by the learning rate). This gives:

  • Interpretability: each feature's estimated effect f_j can be plotted directly.
  • Built-in feature selection: features that never improve the fit are never used.
  • Regularisation by early stopping: the number of steps controls model complexity.

P-spline base learners use a cubic B-spline basis with a second-order difference penalty. The penalty of each feature is chosen so that every base learner has the same degrees of freedom (df, default 4), so smooth and wiggly features compete on equal terms. The approach follows Bühlmann & Hothorn (2007) and Schmid & Hothorn (2008).

Installation

pip install cwgboost

Requires Python 3.10+, NumPy and SciPy.

Quick start

import numpy as np
from cwgboost import CWGBoost

rng = np.random.default_rng(0)
X = rng.uniform(-3, 3, (1000, 5))
y = np.sin(X[:, 0]) + X[:, 1] ** 2 / 4 + rng.normal(0, 0.3, 1000)
X_train, X_val, y_train, y_val = X[:800], X[800:], y[:800], y[800:]

model = CWGBoost(n_estimators=2000, learning_rate=0.1, early_stopping_rounds=50)
model.fit(X_train, y_train, eval_set=(X_val, y_val))

model.predict(X_val)                       # predictions
model.score(X_val, y_val)                  # R^2
model.feature_importance(X_val, y_val)     # relative MSE increase without each feature
effects = model.predict_components(X_val)  # (n_samples, n_features) effect of each feature

CWGBoost follows the scikit-learn estimator interface, so it works with clone, pipelines, cross_val_score and GridSearchCV (scikit-learn itself is not required).

Parameters

Parameter Default Description
n_estimators 100 Maximum number of boosting steps.
learning_rate 0.1 Shrinkage applied to each base learner.
base_learner "pspline" "pspline" (smooth effects), "stump" (step functions) or "both" (compete in every step).
df 4 Degrees of freedom of each P-spline base learner.
n_knots 20 Number of equally spaced knots of the B-spline basis.
degree 3 Degree of the B-splines.
penalty_order 2 Order of the difference penalty.
early_stopping_rounds None Stop when the eval_set loss has not improved for this many steps and keep the best ensemble.
verbose 0 Print progress every verbose steps.

After fitting, estimators_ lists the selected base learners, validation_loss_ holds the validation loss after each step, and intercept_ is the starting value (the mean of y).

Outside the range of the training data, P-spline effects are held constant at their boundary value rather than extrapolated.

Only the squared-error loss is implemented.

Examples

The examples/ folder contains:

  • additive_regression.py: fit an additive model and plot the estimated effects.
  • nonlinear_timeseries.py: forecast a regime-switching AR(1) process from its lags.
  • pspline_smoothing.py: smooth a noisy curve with a single P-spline.

Development

pip install -e ".[test]"
pytest
python benchmarks/benchmark.py

References

  • Bühlmann, P. and Hothorn, T. (2007). Boosting algorithms: regularization, prediction and model fitting. Statistical Science, 22(4), 477–505.
  • Schmid, M. and Hothorn, T. (2008). Boosting additive models using component-wise P-splines. Computational Statistics & Data Analysis, 53(2), 298–311.
  • Eilers, P. H. C. and Marx, B. D. (1996). Flexible smoothing with B-splines and penalties. Statistical Science, 11(2), 89–121.

License

BSD 3-Clause, see LICENSE.

Metadata

Release files for cwgboost 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cwgboost 0.1.0
File Size Uploaded Provenance Actions
cwgboost-0.1.0.tar.gz 16.3 kB With provenance Details for cwgboost-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cwgboost 0.1.0
File Interpreter ABI Platform Actions
cwgboost-0.1.0-py3-none-any.whl Python 3 none any Details for cwgboost-0.1.0-py3-none-any.whl

Total release size: 29.1 kB

Release files / cwgboost-0.1.0.tar.gz

Download URL cwgboost-0.1.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0911d3f75bd37639cb7419ae2d9eca9f06dd66c50d246749ac1422fa108e4121
BLAKE2b-256 checksum
How to use checksums
e6ccd0c2d9b481948914ebd96dda069b4660217cc2c5a77eaf32f7a5fb50f07a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Release files / cwgboost-0.1.0-py3-none-any.whl

Download URL cwgboost-0.1.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a95ff3ea3f839428a9a89418ad4e10c53f435d18a2026b0b2afd288475c25eb2
BLAKE2b-256 checksum
How to use checksums
4f98849e62bd827560d7bb6db891363c8688b44b05dc7eb3d4fafcb0cea68d13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Security for cwgboost 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cwgboost-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page