Metadata-Version: 2.4
Name: modelmatrix
Version: 0.1.0
Summary: Model matrices from tabular data, as scikit-learn transformers
Author-email: Jonathan Taylor <jonathan.taylor@stanford.edu>
License-Expression: BSD-3-Clause
Project-URL: Homepage, https://github.com/intro-stat-learning/modelmatrix
Project-URL: Documentation, https://intro-stat-learning.github.io/modelmatrix
Project-URL: Changelog, https://github.com/intro-stat-learning/modelmatrix/blob/main/CHANGELOG.md
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.7.1
Requires-Dist: pandas>=1.5
Requires-Dist: scipy>=0.9
Requires-Dist: scikit-learn>=1.2
Requires-Dist: narwhals>=1.26
Requires-Dist: joblib
Provides-Extra: doc
Requires-Dist: jupyter-book<3,>=2; extra == "doc"
Requires-Dist: sphinx; extra == "doc"
Requires-Dist: sphinx-book-theme; extra == "doc"
Requires-Dist: statsmodels; extra == "doc"
Requires-Dist: patsy; extra == "doc"
Requires-Dist: formulaic; extra == "doc"
Requires-Dist: polars; extra == "doc"
Requires-Dist: rpy2; extra == "doc"
Requires-Dist: jupytext; extra == "doc"
Dynamic: license-file

# 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`.

```python
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](https://www.statlearning.com),
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.
