Skip to main content

modelmatrix

Model matrices from tabular data, as scikit-learn transformers.

ModelSpec builds a design matrix from a pd.DataFrame (or a polars or pyarrow frame, or an np.ndarray) from a list of terms: columns, categorical encodings, polynomials, splines, principal components and their interactions. It is a scikit-learn transformer, so it goes in a Pipeline, is cloned and cross-validated, and the parameters of its terms are tuned with GridSearchCV.

from modelmatrix import ModelSpec, ns, poly
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import make_pipeline

spec = ModelSpec([ns('age', df=4), poly('year', 2), 'education',
                  ('age', 'education')])
X = spec.fit_transform(Wage)

pipe = make_pipeline(spec, LinearRegression())
grid = GridSearchCV(pipe, {'modelspec__terms__0__df': [2, 4, 8]})
grid.fit(Wage, Wage['wage'])

ModelSpec was written for the labs of An Introduction to Statistical Learning with Python, and from ISLP.models import ModelSpec still works there.

Documentation: https://intro-stat-learning.github.io/modelmatrix

Install

pip install modelmatrix

Requires Python 3.11 or later. BSD licensed.

Metadata

Release files for modelmatrix 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modelmatrix 0.3.0
File Size Uploaded Provenance Actions
modelmatrix-0.3.0.tar.gz 125.9 kB Without provenance Details for modelmatrix-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for modelmatrix 0.3.0
File Interpreter ABI Platform Actions
modelmatrix-0.3.0-py3-none-any.whl Python 3 none any Details for modelmatrix-0.3.0-py3-none-any.whl

Total release size: 162.2 kB

Release files / modelmatrix-0.3.0.tar.gz

Download URL modelmatrix-0.3.0.tar.gz
Size 125.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f843531c78bde9c693ef41c2ffe64c34c009b558b3fb7f33f6e8c46036779c8d
BLAKE2b-256 checksum
How to use checksums
7de8127d10784f08fe92b03a1d5076cdd2a78da8721923e37192bd3f5931bd51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / modelmatrix-0.3.0-py3-none-any.whl

Download URL modelmatrix-0.3.0-py3-none-any.whl
Size 36.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b54af3f71036d2ab93573e371e90d1714694d721bb532a51e7cfa9ad61a16e40
BLAKE2b-256 checksum
How to use checksums
1ab8d9e63282241807dc9b030ff9d5d4baab1d1806b9f4f5058957fa3e9a4f43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for modelmatrix 0.3.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page