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.2.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.2.0
File Size Uploaded Provenance Actions
modelmatrix-0.2.0.tar.gz 122.2 kB Without provenance Details for modelmatrix-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 156.1 kB

Release files / modelmatrix-0.2.0.tar.gz

Download URL modelmatrix-0.2.0.tar.gz
Size 122.2 kB
Tags Source
SHA-256 checksum
How to use checksums
92b2475e48c53e41012fdc5b65706853c383db288f82cffa9e09121dac18d456
BLAKE2b-256 checksum
How to use checksums
60039c6ef244460eea3f3e43880256eeaac702b1f406ebd37f7f6a2a57e2ead7
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.2.0-py3-none-any.whl

Download URL modelmatrix-0.2.0-py3-none-any.whl
Size 34.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6aebc7813c59dd5dfc732b3202b9f4ddff066d36dbf52423b86e405f5d437852
BLAKE2b-256 checksum
How to use checksums
d9f028e128184520f664a9ba33b5e0079e00de2626a610295b73eaf4ffab2585
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.2.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