XGBoostLSS

repository·master·Indexed 20 days ago

https://github.com/statmixedml/xgboostlss

An extension of XGBoost for probabilistic modelling that predicts the full conditional distribution of univariate and multivariate targets. Version 0.6.1 leverages PyTorch and Pyro to support continuous, discrete, and mixed distributions, including Normalizing Flows and Mixture-Densities. It implements Distributional Gradient Boosting Machines (DGBM) to estimate location, scale, and shape parameters, providing support for zero-inflated data, automatic differentiation for gradients and Hessians, and compatibility with SHAP and Optuna.

Tokens
8.3K
Snippets
16
Records
31
Agent score
71%

What's inside xgboostlss

  1. Overview of XGBoostLSS features

    master

    XGBoostLSS is an extension of XGBoost designed for probabilistic modelling. It allows you to model and predict the full conditional distribution of univariate and multivariate targets as a function of covariates.

    Key capabilities include:

    • Distributional Parameter Estimation: Estimates all parameters of the chosen distribution.
    • Complex Distributions: Supports Normalizing Flows for multi-modal distributions and Mixture-Densities for diverse data characteristics.
    • Multivariate Support: Multi-target regression for modelling multivariate responses and their dependencies.
    • Zero-Handling: Zero-Adjusted and Zero-Inflated distributions for data with an excess of zeros.
    • Automatic Differentiation: Uses PyTorch to automatically derive Gradients and Hessians of distributional parameters.
    • Optimization: Automated hyper-parameter search (including pruning) via Optuna.
    • Interpretability: Compatible with SHapley Additive exPlanations (SHAP).
    • XGBoost Compatibility: Maintains full compatibility with standard XGBoost features.
  2. Understand XGBoostLSS runtime complexity

    master

    XGBoostLSS uses a one vs. all estimation strategy. This means a separate tree is grown for every distributional parameter being estimated.

    Runtime Calculation: Total trees trained = [number of iterations] * [number of distributional parameters]

    Implications:

    • Univariate distributions: Runtime is higher than standard XGBoost (which only trains [number of iterations] trees).
    • Multivariate targets: Estimation can become computationally expensive as the number of parameters increases with the number of targets and their dependencies.
  3. How GAMLSS works for univariate targets

    master

    Generalized Additive Models for Location, Scale, and Shape (GAMLSS) is a framework for distributional modeling where a univariate response $y$ follows a distribution $\mathcal{D}(\boldsymbol{\theta}(x))$ that depends on covariates.

    In this framework, the distributional parameters $\boldsymbol{\theta}(x)$ are modeled as functions of explanatory variables. A typical parameter set includes:

    • Location ($\mu$): The center of the distribution.
    • Scale ($\sigma^2$): The spread or variance.
    • Shape ($\nu, \tau$): Parameters controlling skewness and kurtosis.

    Unlike Generalized Linear Models (GLM), GAMLSS relaxes the assumption of the exponential family, allowing for highly skewed, kurtotic, discrete, or zero-inflated distributions. XGBoostLSS extends this by using tree-based models to estimate these parameter functions $\eta_{k} = f_{k}(\mathbf{x})$.

  4. Use Normalizing Flows for complex distributions

    master

    When parametric distributions (like Gaussian or Poisson) are not flexible enough to approximate your dataset—for example, when dealing with multi-modal distributions—you can use Normalizing Flows in XGBoostLSS.

    Normalizing Flows approximate the data non-parametrically by transforming a simple base distribution (e.g., $N(0,1)$) into a complex target distribution through a series of bijective transformations. This approach allows for fitting highly complex distributions with relatively few parameters.

    In XGBoostLSS, the implementation is based on element-wise rational splines (linear or quadratic order), providing a balance of functional flexibility and numerical stability.

  5. Understand Distributional Gradient Boosting Machines (DGBM)

    master

    Traditional regression models often focus only on estimating the conditional mean $\mathbb{E}(Y|\mathbf{X} = \mathbf{x})$, which implicitly assumes a Normal distribution with constant variance. Distributional Gradient Boosting Machines (DGBM) extend this by modeling the entire conditional distribution $F_{Y}(y|\mathbf{x})$.

    This approach is useful when data exhibits:

    • Heteroskedasticity: Varying levels of variance.
    • Skewness: Asymmetric distributions.
    • Kurtosis: Varying degrees of 'tailedness'.
    • Multimodality: Data arising from multiple underlying processes.

    By modeling all distributional parameters (location, scale, shape, etc.) as functions of covariates, DGBM provides a more complete picture of uncertainty and the data generating process compared to standard point-forecast models.

  6. Use Mixture Distributions for complex data shapes

    master

    Mixture distributions allow you to model data that arises from multiple underlying processes by using a weighted combination of several component distributions. This is particularly effective for capturing multimodal distributions (data with multiple peaks).

    A mixture density is represented as:

    $$f\bigl(y_{i} | \boldsymbol{\theta}{i}(x{i})\bigr) = \sum_{m=1}^{M} w_{i,m}(x_{i}) \cdot f_{m}\bigl(y_{i} | \boldsymbol{\theta}{i,m}(x{i})\bigr)$$

    Key components include:

    • Component densities ($f_m$): Individual distributions (e.g., Gaussian, StudentT).
    • Parameters ($\boldsymbol{\theta}_{i,m}$): Parameters for each component, which can depend on covariates.
    • Mixing coefficients ($w_{i,m}$): Weights indicating the importance of each component, also modeled as functions of covariates.

    In XGBoostLSS, you can use combinations of the same distribution type with different parameterizations, such as Gaussian-Mixture or StudentT-Mixture.

  7. How XGBoostLSS (GBMLSS) works

    master

    XGBoostLSS (Gradient Boosting Machines for Location, Scale and Shape) extends the standard XGBoost framework to probabilistic modeling.

    Core Mechanics:

    • Multi-parameter Optimization: A separate tree is grown for each parameter of the chosen distribution.
    • Automatic Differentiation: Gradients and Hessians (the first and second order derivatives of the log-likelihood) are derived using PyTorch. This allows users to implement custom parametric distributions or use Normalizing Flows without manually deriving complex derivatives.
    • Simultaneous Estimation: Gradients, Hessians, and the loss function are evaluated simultaneously for all parameters.
    • Stability: To improve convergence, unconditional Maximum Likelihood (ML) estimates of the parameters are used as offset values.
    • Interpretability: The framework provides attribute importance and partial dependence plots using the Shapley-Value (SHAP) approach to help understand the data generating process.
  8. Model multivariate targets with XGBoostLSS

    master

    XGBoostLSS supports multivariate distributional regression to model dependencies in $D$-dimensional responses $\mathbf{y} = (y_{i1}, \ldots, y_{iD})^{T}$.

    Instead of modeling each dimension independently, the framework relates all parameters $\theta_{k}$ of a multivariate density to the covariates $\mathbf{x}$. Common modeling approaches include:

    • Multivariate Gaussian: Modeling the conditional mean vector $\mu_{\mathbf{x}}$ and a positive definite symmetric covariance matrix $\Sigma_{\mathbf{x}}$.
    • Bivariate Modeling: For $D=2$, the covariance matrix $\Sigma_{\mathbf{x}}$ is parameterized using variances $\sigma^2$ and correlations $\rho$.
    • Covariance Approximations: Using Cholesky Decomposition or Low-Rank Covariance approximations to manage the covariance matrix structure.
  9. Improve convergence with stabilization and standardization

    master

    XGBoostLSS optimizes Gradients and Hessians for distributional parameters. If these values have vastly different magnitudes, convergence may be unstable or slow.

    To improve convergence:

    1. Built-in Stabilization: XGBoostLSS includes internal stabilization for Gradients and Hessians.
    2. Response Standardization: For datasets where the response range differs significantly from the Gradient/Hessian ranges, manually standardize the continuous response variable (e.g., by dividing it by a constant like y/100).

    Evaluate both techniques based on your specific dataset to ensure stable training.

  10. Install XGBoostLSS

    master

    You can install XGBoostLSS via PyPI for the stable version, or directly from the GitHub repository for the development version.

    Install stable version from PyPI

    pip install xgboostlss

    Install development version from GitHub

    pip install git+https://github.com/StatMixedML/XGBoostLSS.git
    pip install xgboostlss
  11. Optimize hyperparameters for XGBoostLSS

    master

    You can tune any XGBoost hyperparameter using the xgblss.hyper_opt method. The param_dict must follow a specific structure based on the parameter type:

    1. Float/Int: {"param_name": ["sample_type", low, high, log]}
      • sample_type: `