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

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: lowess and supsmu matching R's stats::lowess and stats::supsmu to machine precision
  • Demand identification: aid() and aid_cat() for automatic classification of demand series and stockout detection

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.2.tar.gz (165.6 kB view details)

Uploaded Source

Built Distributions

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

greybox-1.0.2-cp313-cp313-win_amd64.whl (280.6 kB view details)

Uploaded CPython 3.13Windows x86-64

greybox-1.0.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (312.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

greybox-1.0.2-cp313-cp313-macosx_11_0_arm64.whl (276.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

greybox-1.0.2-cp313-cp313-macosx_10_13_x86_64.whl (284.9 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

greybox-1.0.2-cp312-cp312-win_amd64.whl (280.6 kB view details)

Uploaded CPython 3.12Windows x86-64

greybox-1.0.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (312.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

greybox-1.0.2-cp312-cp312-macosx_11_0_arm64.whl (276.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

greybox-1.0.2-cp312-cp312-macosx_10_13_x86_64.whl (284.8 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

greybox-1.0.2-cp311-cp311-win_amd64.whl (277.3 kB view details)

Uploaded CPython 3.11Windows x86-64

greybox-1.0.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (308.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

greybox-1.0.2-cp311-cp311-macosx_11_0_arm64.whl (273.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

greybox-1.0.2-cp311-cp311-macosx_10_13_x86_64.whl (279.8 kB view details)

Uploaded CPython 3.11macOS 10.13+ x86-64

greybox-1.0.2-cp310-cp310-win_amd64.whl (276.4 kB view details)

Uploaded CPython 3.10Windows x86-64

greybox-1.0.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (306.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

greybox-1.0.2-cp310-cp310-macosx_11_0_arm64.whl (271.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

greybox-1.0.2-cp310-cp310-macosx_10_13_x86_64.whl (277.9 kB view details)

Uploaded CPython 3.10macOS 10.13+ x86-64

File details

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

File metadata

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

File hashes

Hashes for greybox-1.0.2.tar.gz
Algorithm Hash digest
SHA256 35ad044bdca96c22a0af57048e70b26b387698b3d5564bfa30944c6c48db8e16
MD5 6ec2303f49bd081a2f94bad46701d669
BLAKE2b-256 632ab5ee9e4352024f8a6e037cf09f15e09c47e4b5634e753eaed05d05834c6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2.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.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: greybox-1.0.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 280.6 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for greybox-1.0.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7466aa0ed92ebb35718f30b7fe8fa28346b15e73cdcf2a40f9dcb3c1edde9698
MD5 423914d29364adb4f8a586371e4283aa
BLAKE2b-256 328d4adf23404c8222877149ada398aff9744a262d1701dc5ca38f03c5f1dd47

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp313-cp313-win_amd64.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.

File details

Details for the file greybox-1.0.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dcf56f12b4e9d84ac2506595dd07c15451a460b3a148d2986cc64982be2f21b6
MD5 b8d2ebf6b5d75e4b7825ce0926383a59
BLAKE2b-256 a00c15b9a3cdde2e44c20e94c35e1d4e940f0ff649a241721d3e65e4c5d8505d

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.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.

File details

Details for the file greybox-1.0.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a6349c947a13af4b1255c58b8f862997fb4348a4460ae7dad2cb558dfd71b158
MD5 10969095bf90f72a8c3a58be689aed1a
BLAKE2b-256 7522e39e2b8726796afbbe91216f47401ef155eec240636c601e9e5f0567c2a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp313-cp313-macosx_11_0_arm64.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.

File details

Details for the file greybox-1.0.2-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 fed03b7546a8a3cadd60a60281d8bc81c69854b25f97a425ad77863a1f03e927
MD5 e06b04e9236c36eb88bf47e678467502
BLAKE2b-256 fb777a1b567202ede13675e88d957d21c9cbb6c5d23b17290db4d1b1ebe5d9aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp313-cp313-macosx_10_13_x86_64.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.

File details

Details for the file greybox-1.0.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: greybox-1.0.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 280.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for greybox-1.0.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 eae2adf91b243d64da2e01fe5063a16a507f69a55d9eff86e7e71ed5338f37ee
MD5 6cbd9af053f3156700c50b7cda082d93
BLAKE2b-256 0d9959cf5eb9de8ad874e7bec0ae12583ada62466b94b5a8ecdf7dfff2581d29

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp312-cp312-win_amd64.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.

File details

Details for the file greybox-1.0.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 19b7665556359a6f4bd903c6e7ccaa14e3cd8cb8499af1004431bfecc1edd977
MD5 35d4ab03385f7a64be374f3eddd6e2df
BLAKE2b-256 5b7d50fac7e112ca9975b5a4b5cdc1dcae80ee53e4ff40040eb8422297bb0b6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.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.

File details

Details for the file greybox-1.0.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d99afbae6f3edc1c9f3a5b7838ede276eebd7f9fbc8069ca0cb39790f729930
MD5 6a085342284211748bc8eeaee149cbf5
BLAKE2b-256 426013170456c8e46a96828d88ef237836a0063438e24f080d2639c6acc991b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp312-cp312-macosx_11_0_arm64.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.

File details

Details for the file greybox-1.0.2-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 869579d9b68027364f41d35b2d598f18414aec7b5e77f9a2496dfb4720067cd2
MD5 54ee7cef36d9112e24bf3e2845e58184
BLAKE2b-256 be7605dfee68f4c49e340b0a97ebd539364317c2e880227c3172ef1374f97c83

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp312-cp312-macosx_10_13_x86_64.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.

File details

Details for the file greybox-1.0.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: greybox-1.0.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 277.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for greybox-1.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1b6585285510fa0457afd3e659f7fed56b19df60e760f4807a474d1c4defbe41
MD5 db2bb8fa7efe69425f25e2ebba5e08f9
BLAKE2b-256 8c55ce5a18a685dc375a7054f843eb21eb99d639e334bb3bcd09b9ab61f9cf59

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp311-cp311-win_amd64.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.

File details

Details for the file greybox-1.0.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e5ca76ec41c47153c52dd9cf2fb8897c0fe48540a384eac9477915692af754b7
MD5 91451de689b9599a206890aa1665f3a3
BLAKE2b-256 a6a02a3381886a192d84b073f91b9e8235fdf3c663dba8b643ab04d05e4b982c

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.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.

File details

Details for the file greybox-1.0.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a2e24f055be2bfd3cf6b8492dc72f9d6aade7b505163b47f1414da6c178bb987
MD5 d527e9aab72c16719bba2c87a2137e2d
BLAKE2b-256 54455dcc930d52f281027c2bd0cc8d9d998bd5a4aadee91ae587454623a79a4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp311-cp311-macosx_11_0_arm64.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.

File details

Details for the file greybox-1.0.2-cp311-cp311-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp311-cp311-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 20c154d3cbd7c8c8a289392d96dc49e2e3d2400daa399deef79a489b63cebc3d
MD5 8f095ffd0154fb80499d461fc6e0d79d
BLAKE2b-256 aed9236171c05ed2856f1921d80ac2c1dde19945e4d9e71cf708bf3fb66f1348

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp311-cp311-macosx_10_13_x86_64.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.

File details

Details for the file greybox-1.0.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: greybox-1.0.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 276.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for greybox-1.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 71c4a2655688e68c6bfb510a897f216d70da5a3b9df42eb9dcda2c7f0a2e55aa
MD5 d830c0aa9ba0c512eedbe7b6c6ba0b00
BLAKE2b-256 da07b61ea0772d7b72975cadec74055b1ed4d5d04b95b7685fcb8173a2f7375f

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp310-cp310-win_amd64.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.

File details

Details for the file greybox-1.0.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7b7fadcbf8293ab66332cce4c1014d86138d3e06281c90c3df19e73810a0724a
MD5 0e4899c0dc44ea29213e1a746672641c
BLAKE2b-256 8b57b01588239c4f7c0ec7ea8cc9825ca845c6afffa7d73c7c88fef13c7c09b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.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.

File details

Details for the file greybox-1.0.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f2e1009fb842eb3ee8b77eab1c29f6d34819e47d9ef2a22f54256489e597626
MD5 9403738a28179d0f594401327b8a07cd
BLAKE2b-256 ed7df66ce79a231785e51dff5c43302d6fa422c2441191a24f2d984a255a3b24

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp310-cp310-macosx_11_0_arm64.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.

File details

Details for the file greybox-1.0.2-cp310-cp310-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for greybox-1.0.2-cp310-cp310-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3f949b45d263b3c5a57d42f46b1fbdbb003b9f842e00c47d796fa6474d168515
MD5 1863be793b45e2acc2cb8857b5de757f
BLAKE2b-256 4df56b09c28d22d37cfd3146f10c64f1a7a58fe5b02d8bb7db97099174884155

See more details on using hashes here.

Provenance

The following attestation bundles were made for greybox-1.0.2-cp310-cp310-macosx_10_13_x86_64.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