Skip to content

Gp

polars_ts.bayesian.gp

Gaussian Process regression for time series forecasting.

Non-parametric Bayesian forecasting with kernels designed for temporal data. Supports exact GP (Cholesky) and sparse GP (inducing points).

References

  • Rasmussen & Williams (2006), Gaussian Processes for Machine Learning
  • Roberts et al. (2013), Gaussian processes for time-series modelling
  • Wilson & Adams (2013), GP Kernels for Pattern Discovery and Extrapolation

Kernel

Base kernel class.

RBFKernel

Bases: Kernel


              flowchart TD
              polars_ts.bayesian.gp.RBFKernel[RBFKernel]
              polars_ts.bayesian.gp.Kernel[Kernel]

                              polars_ts.bayesian.gp.Kernel --> polars_ts.bayesian.gp.RBFKernel
                


              click polars_ts.bayesian.gp.RBFKernel href "" "polars_ts.bayesian.gp.RBFKernel"
              click polars_ts.bayesian.gp.Kernel href "" "polars_ts.bayesian.gp.Kernel"
            

Radial Basis Function (squared exponential) kernel.

Matern32Kernel

Bases: Kernel


              flowchart TD
              polars_ts.bayesian.gp.Matern32Kernel[Matern32Kernel]
              polars_ts.bayesian.gp.Kernel[Kernel]

                              polars_ts.bayesian.gp.Kernel --> polars_ts.bayesian.gp.Matern32Kernel
                


              click polars_ts.bayesian.gp.Matern32Kernel href "" "polars_ts.bayesian.gp.Matern32Kernel"
              click polars_ts.bayesian.gp.Kernel href "" "polars_ts.bayesian.gp.Kernel"
            

Matern 3/2 kernel.

Matern52Kernel

Bases: Kernel


              flowchart TD
              polars_ts.bayesian.gp.Matern52Kernel[Matern52Kernel]
              polars_ts.bayesian.gp.Kernel[Kernel]

                              polars_ts.bayesian.gp.Kernel --> polars_ts.bayesian.gp.Matern52Kernel
                


              click polars_ts.bayesian.gp.Matern52Kernel href "" "polars_ts.bayesian.gp.Matern52Kernel"
              click polars_ts.bayesian.gp.Kernel href "" "polars_ts.bayesian.gp.Kernel"
            

Matern 5/2 kernel.

PeriodicKernel

Bases: Kernel


              flowchart TD
              polars_ts.bayesian.gp.PeriodicKernel[PeriodicKernel]
              polars_ts.bayesian.gp.Kernel[Kernel]

                              polars_ts.bayesian.gp.Kernel --> polars_ts.bayesian.gp.PeriodicKernel
                


              click polars_ts.bayesian.gp.PeriodicKernel href "" "polars_ts.bayesian.gp.PeriodicKernel"
              click polars_ts.bayesian.gp.Kernel href "" "polars_ts.bayesian.gp.Kernel"
            

Periodic kernel for repeating patterns.

SpectralMixtureKernel

Bases: Kernel


              flowchart TD
              polars_ts.bayesian.gp.SpectralMixtureKernel[SpectralMixtureKernel]
              polars_ts.bayesian.gp.Kernel[Kernel]

                              polars_ts.bayesian.gp.Kernel --> polars_ts.bayesian.gp.SpectralMixtureKernel
                


              click polars_ts.bayesian.gp.SpectralMixtureKernel href "" "polars_ts.bayesian.gp.SpectralMixtureKernel"
              click polars_ts.bayesian.gp.Kernel href "" "polars_ts.bayesian.gp.Kernel"
            

Spectral mixture kernel (Wilson & Adams 2013).

SumKernel

Bases: Kernel


              flowchart TD
              polars_ts.bayesian.gp.SumKernel[SumKernel]
              polars_ts.bayesian.gp.Kernel[Kernel]

                              polars_ts.bayesian.gp.Kernel --> polars_ts.bayesian.gp.SumKernel
                


              click polars_ts.bayesian.gp.SumKernel href "" "polars_ts.bayesian.gp.SumKernel"
              click polars_ts.bayesian.gp.Kernel href "" "polars_ts.bayesian.gp.Kernel"
            

Sum of two kernels.

ProductKernel

Bases: Kernel


              flowchart TD
              polars_ts.bayesian.gp.ProductKernel[ProductKernel]
              polars_ts.bayesian.gp.Kernel[Kernel]

                              polars_ts.bayesian.gp.Kernel --> polars_ts.bayesian.gp.ProductKernel
                


              click polars_ts.bayesian.gp.ProductKernel href "" "polars_ts.bayesian.gp.ProductKernel"
              click polars_ts.bayesian.gp.Kernel href "" "polars_ts.bayesian.gp.Kernel"
            

Product of two kernels.

GPResult dataclass

Gaussian Process regression result.

Attributes

kernel Fitted kernel (with optimized hyperparameters). noise_var Optimized observation noise variance. X_train Training time indices. y_train Training observations. alpha Cholesky solve vector for predictions. L Lower Cholesky factor of training covariance.

GaussianProcessTS

Gaussian Process time series forecaster.

Parameters

kernel Kernel name or Kernel instance. Default "rbf". optimize Whether to optimize hyperparameters via marginal likelihood. noise_var Initial observation noise variance. coverage Credible interval coverage (default 0.9). id_col Column identifying each time series. target_col Column with target values. time_col Column with timestamps.

fit(df)

Fit the GP to one or more time series.

predict(df, h)

Generate h-step forecasts with credible intervals.

make_kernel(name, **kwargs)

Create a kernel by name.

_stable_cholesky(K, jitter=1e-06)

Cholesky with increasing jitter for numerical stability.

_neg_log_marginal_likelihood(log_params, X, y, kernel, noise_idx)

Negative log marginal likelihood for hyperparameter optimization.

_optimize_hyperparams(X, y, kernel, noise_var)

Optimize kernel hyperparameters via marginal likelihood.

gp_forecast(df, h, kernel='rbf', optimize=True, noise_var=0.1, coverage=0.9, id_col='unique_id', target_col='y', time_col='ds')

Gaussian Process forecasting convenience function.

Parameters

df Input DataFrame. h Forecast horizon. kernel Kernel name or instance. Default "rbf". optimize Optimize hyperparameters via marginal likelihood. noise_var Initial noise variance. coverage Credible interval coverage (default 0.9). id_col, target_col, time_col Column names.

Returns

pl.DataFrame Forecasts with y_hat, y_hat_lower, y_hat_upper.