Weight Transformations#
Functions#
generate_increasing_weights#
- iguanas.weight_transformations.generate_increasing_weights(X: polars.Series | polars.DataFrame, powers: numpy.ndarray | None = None) polars.DataFrame[source]#
Generate weight transformations where larger input values receive larger weights.
- Parameters:
X (pl.Series | pl.DataFrame) – Numerical Polars Series or DataFrame to transform. If a DataFrame, transformations are applied to each column and concatenated horizontally.
powers (np.ndarray | None, default=[0.25, 0.5, 1.0, 2.0, 4.0]) – Power values for polynomial transformations.
- Returns:
Each column is a different weight transformation (baseline, powers, log).
- Return type:
pl.DataFrame
Examples
>>> import polars as pl >>> s = pl.Series("amount", [0.0, 10.0, 50.0, 100.0]) >>> df = generate_increasing_weights(s) >>> df.columns # 'Baseline', '(1+x)^0.25__amount', ..., 'log(1+x)__amount' >>> # DataFrame input: each column processed independently >>> X = pl.DataFrame({"a": [1.0, 2.0, 3.0], "b": [4.0, 5.0, 6.0]}) >>> generate_increasing_weights(X).shape (3, ...) # 1 Baseline + 5 power cols + 1 log col per feature, minus duplicate Baselines
generate_decreasing_weights#
- iguanas.weight_transformations.generate_decreasing_weights(X: polars.Series | polars.DataFrame, powers: numpy.ndarray | None = None) polars.DataFrame[source]#
Generate weight transformations where smaller input values receive larger weights.
- Parameters:
X (pl.Series | pl.DataFrame) – Numerical Polars Series or DataFrame to transform. If a DataFrame, transformations are applied to each column and concatenated horizontally.
powers (np.ndarray | None, default=[0.25, 0.5, 1.0, 2.0, 4.0]) – Power values for reciprocal transformations (1/(1+x)^power).
- Returns:
Each column is a different inverse weight transformation.
- Return type:
pl.DataFrame
Examples
>>> import polars as pl >>> s = pl.Series("amount", [0.0, 10.0, 50.0, 100.0]) >>> df = generate_decreasing_weights(s) >>> df.columns # '1/(1+x)__amount', '1/(1+x)^0.25__amount', ..., '1/log(1+x)__amount'
generate_weights#
- iguanas.weight_transformations.generate_weights(X: polars.Series | polars.DataFrame, powers: numpy.ndarray | None = None) polars.DataFrame[source]#
Generate all weight transformations (increasing and decreasing).
- Parameters:
X (pl.Series | pl.DataFrame) – Numerical Polars Series or DataFrame to transform. If a DataFrame, transformations are applied to each column and concatenated horizontally.
powers (np.ndarray | None, default=[0.25, 0.5, 1.0, 2.0, 4.0]) – Power values used for both increasing and decreasing transformations.
- Returns:
Combined increasing and decreasing weight transformations in one DataFrame.
- Return type:
pl.DataFrame
Examples
>>> import polars as pl >>> s = pl.Series("amount", [0.0, 10.0, 50.0, 100.0]) >>> df = generate_weights(s) >>> # Columns include both (1+x)^p and 1/(1+x)^p families plus log variants