Categorical#
- class superglm.Categorical(
- base: Literal['most_exposed', 'first'] | str = 'most_exposed',
- grouping=None,
- *,
- levels=None,
- unseen: Literal['error', 'base'] | str = 'error',
- constraint: ConstraintSpec | ConstraintRules | None = None,
Bases:
objectOne-hot encoded categorical feature.
- Parameters:
- basestr
How to choose the reference level.
'most_exposed'- level with highest total sample_weight (default, best for insurance)'first'- first level in the level universe (alphabetical when inferred, as declared whenlevels=or a categorical dtype bounds it)
Or pass a specific level name as a string.
- groupingLevelGrouping, optional
Collapse original levels into groups before fitting.
- levelslist | tuple | Series | ndarray | CategoricalDtype, optional
The level universe to bind to. With a
groupingthis declares the RAW, pre-collapse universe, which the grouping must cover exactly. Levels with no training rows are pinned to base rather than dropped; training rows outside the universe are an error.- unseenstr
Predict-time policy for levels outside the universe.
'error'(default) raises;'base'routes those rows, raw labels agroupingdoes not know included, to the base level with one warning per call. Any other value names a group ofgroupingwhose effect those levels then take, again with one warning per call; the fit checks that the group exists and has a place in the fitted universe.- constraintConstraintSpec | ConstraintRules, optional
A relativity cap,
Constraint.fit.cap(lo, hi): every level’s printed relativity against the base lies in[lo, hi](needs a log link). A shape rule needs ordered levels; useOrderedCategoricalfor one.
- property constraint_rules: ConstraintRules#
The fit-time rules this term carries: a cap, or none.
- adopt_dtype_categories(categories: list) None#
Adopt a dtype-declared universe unless one is already declared.
- apply_level_binding(binding) None#
Adopt a full-frame binding: universe if unset, base pin if unpinned.
- resolve_binding(
- values: NDArray,
- sample_weight=None,
Compute this spec’s full-frame binding without mutating the spec.
- build( ) GroupInfo#
Build sparse one-hot design columns, choosing the base level from x.
- transform(
- x: NDArray,
One-hot encode using levels learned during build().