Skip to main content

An implementation of Wilkinson formulas.

Project description

Formulaic

PyPI - Version PyPI - Python Version PyPI - Status build codecov

Formulaic is a high-performance implementation of Wilkinson formulas for Python.

Note: This project, while largely complete, is still a work in progress, and the API is subject to change between major versions (0.<major>.<minor>).

It provides:

  • high-performance dataframe to model-matrix conversions.
  • support for reusing the encoding choices made during conversion of one data-set on other datasets.
  • extensible formula parsing.
  • extensible data input/output plugins, with implementations for:
    • input:
      • pandas.DataFrame
      • pyarrow.Table
    • output:
      • pandas.DataFrame
      • numpy.ndarray
      • scipy.sparse.CSCMatrix
  • support for symbolic differentiation of formulas (and hence model matrices).

Example code

import pandas
from formulaic import Formula

df = pandas.DataFrame({
    'y': [0,1,2],
    'x': ['A', 'B', 'C'],
    'z': [0.3, 0.1, 0.2],
})

y, X = Formula('y ~ x + z').get_model_matrix(df)

y =

y
0 0
1 1
2 2

X =

Intercept x[T.B] x[T.C] z
0 1.0 0 0 0.3
1 1.0 1 0 0.1
2 1.0 0 1 0.2

Benchmarks

Formulaic typically outperforms R for both dense and sparse model matrices, and vastly outperforms patsy (the existing implementation for Python) for dense matrices (patsy does not support sparse model matrix output).

Benchmarks

For more details, see here.

Related projects and prior art

  • Patsy: a prior implementation of Wilkinson formulas for Python, which is widely used (e.g. in statsmodels). It has fantastic documentation (which helped bootstrap this project), and a rich array of features.
  • StatsModels.jl @formula: The implementation of Wilkinson formulas for Julia.
  • R Formulas: The implementation of Wilkinson formulas for R, which is thoroughly introduced here. [R itself is an implementation of S, in which formulas were first made popular].
  • The work that started it all: Wilkinson, G. N., and C. E. Rogers. Symbolic description of factorial models for analysis of variance. J. Royal Statistics Society 22, pp. 392–399, 1973.

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

formulaic-0.2.4.tar.gz (198.0 kB view details)

Uploaded Source

Built Distribution

formulaic-0.2.4-py3-none-any.whl (56.0 kB view details)

Uploaded Python 3

File details

Details for the file formulaic-0.2.4.tar.gz.

File metadata

  • Download URL: formulaic-0.2.4.tar.gz
  • Upload date:
  • Size: 198.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.10

File hashes

Hashes for formulaic-0.2.4.tar.gz
Algorithm Hash digest
SHA256 15b71ea8972fb451f80684203cddd49620fc9ed5c2e35f31e0874e9c41910d1a
MD5 32bcc01aa3eceb15f303cc751e8d27b6
BLAKE2b-256 1086c3255d462924b40912fe6a8700ed3df377c24ddcd2aa1013234bf34f670d

See more details on using hashes here.

Provenance

File details

Details for the file formulaic-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: formulaic-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 56.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.10

File hashes

Hashes for formulaic-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 775620d93f24f01b33a17aa2cf65a04112003c5112f12015368e4e4605a5013b
MD5 668b6e83c522647b4e47b0a58ba1398c
BLAKE2b-256 45403c337ed87b8ffeb129f21db97bce3d4f1e9125ed4697969348bb6f871931

See more details on using hashes here.

Provenance

Supported by

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