models.columns#
Module: models.columns#
Inheritance diagram for ISLP.models.columns:
Column#
- class ISLP.models.columns.Column(idx: Any, name: str, is_categorical: bool = False, is_ordinal: bool = False, columns: tuple = (), encoder: Any = None)#
Bases:
NamedTupleA column extractor with a possible encoder (following sklearn fit/transform template).
Methods
count(value, /)Return number of occurrences of value.
fit_encoder(X)Fit self.encoder.
get_columns(X[, fit, sparse])Extract associated column from X, encoding it with self.encoder if not None.
index(value[, start, stop])Return first index of value.
- __init__(*args, **kwargs)#
- count(value, /)#
Return number of occurrences of value.
- fit_encoder(X)#
Fit self.encoder.
- Parameters:
- Xarray-like
X on which encoder will be fit.
- Returns:
- None
- get_columns(X, fit=False, sparse=False)#
Extract associated column from X, encoding it with self.encoder if not None.
- Parameters:
- Xarray-like
X on which model matrix will be evaluated. If a pd.DataFrame or pd.Series, variables that are of categorical dtype will be treated as categorical.
- fitbool
If True, fit self.encoder on corresponding column (if it is not already fit). The encoder must be fit to evaluate the columns: a Column used in the terms of a ModelSpec is not itself fit when the ModelSpec is, as a copy of it is.
- sparsebool
If True, the columns may be returned as a scipy.sparse matrix, e.g. for a categorical encoding.
- Returns:
- colsnp.ndarray
Evaluated columns – if an encoder is used, several columns may be produced.
- names(str,)
Column names
- index(value, start=0, stop=sys.maxsize, /)#
Return first index of value.
Raises ValueError if the value is not present.