Skip to content

lazymatrix.RowNormalization ​

LazyMatrix for Python · 0.5.0

Source

Bases: _Normalization

python
RowNormalization(
    *,
    center: Union[bool, typing.Literal["none", "mean", "min", "median"]] = True,
    scale: Union[bool, typing.Literal["none", "sd", "range", "quantile_range", "maxabs", "l1", "l2"]] = True,
    df: int = 0,
    quantile_range: tuple[float, float] = (0.25, 0.75),
    unit_variance: bool = False
)

An immutable recipe for fitting each row independently.

The keyword-only center, scale, df, quantile_range, and unit_variance options follow LazyMatrix with axis=1. Defaults select means and population standard deviations. fit returns RowNormalizationParams, and fit_apply returns a LazyMatrix. Fit new samples with another call to fit_apply; saved row parameters apply only to the rows for which they were fitted. Options are available as read-only properties.

Examples ​

python
>>> recipe = RowNormalization(center=False, scale="l2")
>>> train = recipe.fit_apply(np.array([[3.0, 4.0], [0.0, 0.0]]))
>>> validation = recipe.fit_apply(np.array([[0.0, 2.0]]))
>>> validation.toarray()
array([[0., 1.]])

__init__ {#init} ​

python
__init__(
    *,
    center: Union[bool, typing.Literal["none", "mean", "min", "median"]] = True,
    scale: Union[bool, typing.Literal["none", "sd", "range", "quantile_range", "maxabs", "l1", "l2"]] = True,
    df: int = 0,
    quantile_range: tuple[float, float] = (0.25, 0.75),
    unit_variance: bool = False
) -> None

Source

fit ​

python
fit(X: typing.Any) -> lazymatrix.RowNormalizationParams

Source

Fit row parameters without retaining the input matrix.

Input is copied temporarily using LazyMatrix’s storage rules. Only fitted centers, scales, and nrows are retained. The recipe stays unchanged.

fit_apply ​

python
fit_apply(X: typing.Any) -> lazymatrix.LazyMatrix

Source

Fit each row independently and return a lazy matrix owning its input copy.

Every call fits fresh row parameters, including calls on new samples. Products use the saved values without refitting. Input storage and lazy operations follow LazyMatrix with axis=1.

Released under the MIT and Apache 2.0 licenses.