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.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| modelmatrix-0.1.0.tar.gz | 108.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| modelmatrix-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 135.6 kB
Release files / modelmatrix-0.1.0.tar.gz
| Download URL | modelmatrix-0.1.0.tar.gz |
|---|---|
| Size | 108.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb0fbca252a5c213479a3f077616830a2970afc492ee9f708d7417965ef44f65
|
|
BLAKE2b-256 checksum How to use checksums |
e4b4dfcf0e9df8bd086ae76badb4d8fea1504ef86a43ac934f3d126f30291523
|
| 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.1.0-py3-none-any.whl
| Download URL | modelmatrix-0.1.0-py3-none-any.whl |
|---|---|
| Size | 26.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b3d21ecc81f86b5b11d71285b5f16dcab3bf4e76a09fd9b821bc75800b5b389
|
|
BLAKE2b-256 checksum How to use checksums |
30d25a096fb5eebf99616bb54a02ef6278278aebdbce714880fd00e1e7a7e120
|
| 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.1.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.