models.Terms
The terms of a model: an intercept, numeric columns and factors.
Usage
models.Terms()Build them up, then fit them to training data to learn the factor levels; the result builds the same design matrix on any data.
Examples
>>> from prospicio.models import Terms
>>> data = {"age": [30.0, 45.0, 60.0], "region": ["N", "S", "W"]}
>>> coding = Terms().intercept().numeric("age").factor("region").fit(data)
>>> coding.names[‘(Intercept)’, ‘age’, ‘region[S]’, ‘region[W]’]
Methods
| Name | Description |
|---|---|
| factor() | Adds a factor in treatment coding. |
| fit() | Learns factor levels from training data. |
| intercept() | Adds an intercept. |
| numeric() | Adds a numeric column. |
factor()
Adds a factor in treatment coding.
Usage
factor(name, reference=None)Parameters
name: strreference: str = None- Reference level; the first in sorted order by default.
Returns
Terms
fit()
Learns factor levels from training data.
Usage
fit(data)Parameters
data: dict of str to list- Numeric columns as lists of numbers, factors as lists of strings.
Returns
Coding
Raises
ValueError- If a column is missing or has the wrong kind.
intercept()
Adds an intercept.
Usage
intercept()Returns
Terms
numeric()
Adds a numeric column.
Usage
numeric(name)Parameters
name: str
Returns
Terms