greybox
Python port of the R greybox package — a toolbox for regression model building and forecasting.
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 |
Smoothers (lowess, supsmu)
See the Smoothers wiki page for the full reference.
Non-parametric smoothers that reproduce R's stats::lowess and stats::supsmu to machine precision (native pybind11 implementations).
import numpy as np
from greybox import lowess, supsmu
rng = np.random.default_rng(0)
x = np.linspace(0, 6, 80)
y = np.sin(x) + rng.normal(0, 0.2, 80)
# Cleveland's LOWESS — robust local regression
lo = lowess(x, y, f=0.4)
print(lo["x"], lo["y"]) # sorted x, smoothed y
# Friedman's SuperSmoother — variable-span cross-validation
sm_cv = supsmu(x, y) # automatic span selection
sm_fixed = supsmu(x, y, span=0.3) # fixed span
References: Cleveland (1979) for LOWESS, Friedman (1984) for SuperSmoother.
Automatic Identification of Demand (aid, aid_cat)
See the AID wiki page for the full reference.
Classifies a time series into one of six demand types and flags stockouts, new products, and obsolete products. Port of R's greybox::aid() / aidCat().
import numpy as np
import matplotlib.pyplot as plt
from greybox import aid, aid_cat
rng = np.random.default_rng(42)
# Intermittent count demand: Poisson(0.7)
y = rng.poisson(0.7, 120).astype(float)
result = aid(y)
print(result) # human-readable summary
print(result.name) # e.g. "smooth intermittent count"
print(result.type.type1) # "count" or "fractional" — R-style attribute access
print(result.type["type1"]) # dict-style fallback also works
# Detect injected stockouts and plot them
y2 = rng.poisson(3, 100).astype(float)
y2[40:50] = 0
result2 = aid(y2)
print(result2.stockouts.start, result2.stockouts.end) # 1-based, [41] [50]
ax = result2.plot() # series + grey-shaded stockout span
plt.show()
# Apply to multiple series at once
series = {
"a": rng.poisson(1, 80).astype(float),
"b": rng.poisson(5, 80).astype(float),
"c": rng.normal(10, 2, 80),
}
cat = aid_cat(series)
print(cat.types) # 2x3 demand-category frequency table
print(cat.anomalies) # counts of new / stockouts / old products
ax = cat.plot() # 2x3 demand-category panel
plt.show()
The nested type and stockouts fields are typed dataclasses that
support both result.stockouts.start (R-style attribute access) and
result.stockouts["start"] (dict-style fallback).
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
- Smoothers:
lowessandsupsmumatching R'sstats::lowessandstats::supsmuto machine precision - Demand identification:
aid()andaid_cat()for automatic classification of demand series and stockout detection - Method comparison (RMCB):
rmcb()for the Nemenyi/MCB test comparing forecasting methods, with"mcb"and"lines"plots
Links
License
About
greybox is developed and maintained by OpenForecast, a demand forecasting and inventory management consultancy. The package implements the methods we use in our consulting and teach in our training courses.
Metadata
Release files for greybox 1.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| greybox-1.0.8.tar.gz | 197.2 kB | Details |
Built distributions (wheels)
Total release size: 6.9 MB
Release files / greybox-1.0.8.tar.gz
| Download URL | greybox-1.0.8.tar.gz |
|---|---|
| Size | 197.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ab069f910ea2bdd1a9bc16adbaf49315da6e0e355f1bff4223c8bf624f06428
|
|
BLAKE2b-256 checksum How to use checksums |
0400bea845f526192cdca31fc4f1af7ed98f25e9af3ba0bbbce7bbe63f224002
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp314-cp314-win_amd64.whl
| Download URL | greybox-1.0.8-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 603.8 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
0ea4e316dfb9206ff6311fff7d7fd7b4e035403d73f59e5dd908e865a8be2b4b
|
|
BLAKE2b-256 checksum How to use checksums |
81ed9f9683deed130e063ac5f4f2550b9e589ea8b9bb76d0fc04f5a78b0fdc9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | greybox-1.0.8-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 427.1 kB |
| Tags | CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
b6e5e7de56e87f730df4a95d32357d433a059e8326206ae905dbce12ee3cd688
|
|
BLAKE2b-256 checksum How to use checksums |
f5faa1b57c62f9f174aca65fcf4bee44349e4a47b21891fa61dd99fd07bdd8c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | greybox-1.0.8-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 375.0 kB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
6068b0cd42934a6cbd1ee905ef7d3c7b1b284523d2fb171be2193fa7ca8f9bdd
|
|
BLAKE2b-256 checksum How to use checksums |
c8025b06516241150b7d150cc33e56d2f601ab57b5efdd9522ee4bf2d80dcd7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp313-cp313-win_amd64.whl
| Download URL | greybox-1.0.8-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 590.4 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
bacadba57634f54157d65393cd46ecdb8b08b707da223770f53d70b97c62fd28
|
|
BLAKE2b-256 checksum How to use checksums |
b49b4cad82cf508c6f2f4f3465936294a26dba662ab7d1bc40b39c2f85cfa73b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | greybox-1.0.8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 426.7 kB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
9bff14d089ddb1288335c5e811689af863e9e324f22efb066973019db94aadb3
|
|
BLAKE2b-256 checksum How to use checksums |
3bca7e5d0110a637973b87166e74d4550837a4f6cd5cb329c9d3eb42e9ab8c1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | greybox-1.0.8-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 374.4 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
49bffdf25160e9b308e2385dbcc6f34b156942e9217efb4cf9d2283740ec9e66
|
|
BLAKE2b-256 checksum How to use checksums |
22919fe66adfe63b7fabfd6baf1efa1335e5e541a86f04aab7d765f97ab7612b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp313-cp313-macosx_10_13_x86_64.whl
| Download URL | greybox-1.0.8-cp313-cp313-macosx_10_13_x86_64.whl |
|---|---|
| Size | 385.8 kB |
| Tags | CPython 3.13 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
eb65d723f6e7fcfcefe460045fc29aa4a6c26512a25c56f254621dcd5aa182e2
|
|
BLAKE2b-256 checksum How to use checksums |
dc405801899aa1cb7a86ffa72a4a1190f7cee1a0c4e9488d0348f664a0e58ba8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp312-cp312-win_amd64.whl
| Download URL | greybox-1.0.8-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 590.3 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6435d6efb2ce71ba16633b20f96865eb9dc8e85b2708f56178f538a86be660df
|
|
BLAKE2b-256 checksum How to use checksums |
f167439312b54264a40f0be43029d7bbac6a4d1a180dfc8e7d41ece8d560d826
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | greybox-1.0.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 426.5 kB |
| Tags | CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
e4ec8c6ee7e7132f820f13f55a2332d221e7db0c981477a263532185dd5a42c3
|
|
BLAKE2b-256 checksum How to use checksums |
00a04911243cd7d9be670bdde243a797f260115dc2e18433b4c22e9744c53a79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | greybox-1.0.8-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 374.4 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5033f4d224eb50abce0a3baaa37400c15aba8f112e547faf0a46dfa8ec6c9df7
|
|
BLAKE2b-256 checksum How to use checksums |
be26e6a129e3d2e0bf07d04b8ff4811a0436a098cb54cfe4bad22e0f440a62cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp312-cp312-macosx_10_13_x86_64.whl
| Download URL | greybox-1.0.8-cp312-cp312-macosx_10_13_x86_64.whl |
|---|---|
| Size | 385.6 kB |
| Tags | CPython 3.12 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
142db21e0282e5571a4d68e6528c9bb4c71beef8a29f1d4404272f3e8efa5e4b
|
|
BLAKE2b-256 checksum How to use checksums |
4b3b2c2f8bd838feaeda8ff415b95f424fc5e9d9a8f7f109b1ed24f2bb621d4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp311-cp311-win_amd64.whl
| Download URL | greybox-1.0.8-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 582.9 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
125f966dc93739375a47958742302a2ede2608e9e914ac607438b0a434cc2310
|
|
BLAKE2b-256 checksum How to use checksums |
9215c0e62ef161e84cce1f47998fb786eed16b8b0c209750cfbb1b8b6e54e75a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | greybox-1.0.8-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 421.1 kB |
| Tags | CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
642c4fe19e0de2811d95e629a02c9106cc52612010c0f1d7c0adc5db527e3de2
|
|
BLAKE2b-256 checksum How to use checksums |
53730612d2cc3ad895c3a977445093912f31bac8568f8a45526c18ea3ea72214
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | greybox-1.0.8-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 369.1 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
26f5c3affa56e9ac5a8e97b5f8f3edad80de173cd6dcb652ed2c4d6a236bf827
|
|
BLAKE2b-256 checksum How to use checksums |
7d17f0b6e1e96b982eee4377836098444d75e7b7fccf2ee131221df3311071c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency logRelease files / greybox-1.0.8-cp311-cp311-macosx_10_13_x86_64.whl
| Download URL | greybox-1.0.8-cp311-cp311-macosx_10_13_x86_64.whl |
|---|---|
| Size | 378.7 kB |
| Tags | CPython 3.11 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
483d99228a7386cdc80e934bbc9cfd6931e69a8d308925420911f6a54c2300e0
|
|
BLAKE2b-256 checksum How to use checksums |
81e974411570e71f6ca6b376c94acdd1045f36fa7f86396d605fd6d0fd29eb34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 2, 2026.
Transparency log