Skip to content

StandardScalerWithDOF

sknnr.transformers.StandardScalerWithDOF

StandardScalerWithDOF(ddof: int = 0)

Bases: StandardScaler

Subclass of StandardScaler that allows specification of degrees of freedom used when calculating standard deviation for scaling.

Parameters:

Name Type Description Default
ddof int

Degrees of freedom used when calculating standard deviation. The divisor used in calculations is N - ddof, where N represents the number of samples.

0

Attributes:

Name Type Description
scale_ ndarray of shape (n_features,)

Per feature relative scaling of the data to achieve zero mean and unit variance with the specified degrees of freedom.

mean_ ndarray of shape (n_features,)

The mean value for each feature in the training set.

var_ ndarray of shape (n_features,)

The variance for each feature in the training set.

n_features_in_ int

Number of features seen during fit.

n_samples_seen_ int

The number of samples processed by the estimator for each feature.

Source code in src/sknnr/transformers/_base.py
def __init__(self, ddof: int = 0):
    super().__init__()
    self.ddof = ddof

Attributes

ddof instance-attribute

ddof = ddof

Functions

fit

fit(X: DataLike, y: DataLike | None = None) -> Self
Source code in src/sknnr/transformers/_base.py
def fit(self, X: DataLike, y: DataLike | None = None) -> Self:
    scaler = super().fit(X, y)

    X_arr = validate_data(
        self,
        X=X,
        accept_sparse=False,
        dtype=FLOAT_DTYPES,
        ensure_all_finite="allow-nan",
        reset=False,
        ensure_min_samples=self.ddof + 1,
    )
    scaler.scale_ = np.std(X_arr, axis=0, ddof=self.ddof)
    return scaler