Skip to main content

Toolbox for model building and forecasting

Project description

greybox

PyPI version PyPI - Downloads Python CI Python versions License: LGPL-2.1

Python port of the R greybox package — a toolbox for regression model building and forecasting.

hex-sticker of the greybox package for Python

Installation

pip install greybox

For more installation options, see the Installation wiki page.

Quick Example

import numpy as np
import pandas as pd
from greybox import ALM, formula

# Generate sample data
np.random.seed(42)
n = 200
data = pd.DataFrame({
    "y": np.random.normal(10, 2, n),
    "x1": np.random.normal(5, 1, n),
    "x2": np.random.normal(3, 1, n),
})
data["y"] = 2 + 0.5 * data["x1"] - 0.3 * data["x2"] + np.random.normal(0, 1, n)

# Parse formula and fit model
y, X = formula("y ~ x1 + x2", data=data)
model = ALM(distribution="dnorm")
model.fit(X, y)

# Summary
print(model.summary())

# Predict with intervals
pred = model.predict(result.data, interval="prediction", level=0.95)
print(pred.mean[:5])

# Include AR terms (ARIMA-like models)
# For example, ARIMA(1,1,0) model with Log-Normal distribution:
model = ALM(distribution="dlnorm", orders=(1, 1, 0))
model.fit(X, y)

Supported Distributions

Category Distributions
Continuous dnorm, dlaplace, ds, dgnorm, dlgnorm, dfnorm, drectnorm, dt
Positive dlnorm, dinvgauss, dgamma, dexp, dchisq
Count dpois, dnbinom, dgeom
Bounded dbeta, dlogitnorm, dbcnorm
CDF-based pnorm, plogis
Other dalaplace, dbinom

Features

  • ALM (Augmented Linear Model): Likelihood-based regression with 26 distributions
  • Formula parser: R-style formulas (y ~ x1 + x2, log(y) ~ ., y ~ 0 + x1) with support for backshift operator
  • stepwise(): IC-based variable selection with partial correlations
  • CALM(): Combine ALM models based on IC weights
  • Forecast error measures: MAE, MSE, RMSE, MAPE, MASE, MPE, sMAPE, and more
  • Variable processing: xreg_expander (lags/leads), xreg_multiplier (interactions), temporal_dummy
  • Distributions: 27 distribution families with density, CDF, quantile, and random generation
  • Association: Partial correlations and measures of association
  • Diagnostics: Model diagnostics and validation

Links

License

LGPL-2.1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

greybox-1.0.1.tar.gz (117.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

greybox-1.0.1-py3-none-any.whl (101.4 kB view details)

Uploaded Python 3

File details

Details for the file greybox-1.0.1.tar.gz.

File metadata

  • Download URL: greybox-1.0.1.tar.gz
  • Upload date:
  • Size: 117.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for greybox-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1165e714241e90efadbf44679220b538d9e7bd6a2d534db942fa06e2ac3f49be
MD5 86eb9ee347bb5b66133d651a1fb01592
BLAKE2b-256 a394b5d23494e9a36f78861e22da8ba4232068dbb9be822cef0da338a2220526

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.1.tar.gz:

Publisher: release.yml on config-i1/greybox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file greybox-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: greybox-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 101.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for greybox-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8edf143198b881fc5467d246cab27c677f6d6792def81baa0c5f40fb32b65f7f
MD5 2068b295be94e42e6caec9135a0a9676
BLAKE2b-256 0b148a91109823122cb7dd18b9b7d121a0feb816bbef5720c444d11b61bfb482

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.1-py3-none-any.whl:

Publisher: release.yml on config-i1/greybox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page