sklearn.utils.sparsefuncs.incr_mean_variance_axis

sklearn.utils.sparsefuncs.incr_mean_variance_axis(X, *, axis, last_mean, last_var, last_n)[source]

Compute incremental mean and variance along an axix on a CSR or CSC matrix.

last_mean, last_var are the statistics computed at the last step by this function. Both must be initialized to 0-arrays of the proper size, i.e. the number of features in X. last_n is the number of samples encountered until now.

Parameters
XCSR or CSC sparse matrix, shape (n_samples, n_features)

Input data.

axisint (either 0 or 1)

Axis along which the axis should be computed.

last_meanfloat array with shape (n_features,)

Array of feature-wise means to update with the new data X.

last_varfloat array with shape (n_features,)

Array of feature-wise var to update with the new data X.

last_nint with shape (n_features,)

Number of samples seen so far, excluded X.

Returns
meansfloat array with shape (n_features,)

Updated feature-wise means.

variancesfloat array with shape (n_features,)

Updated feature-wise variances.

nint with shape (n_features,)

Updated number of seen samples.

Notes

NaNs are ignored in the algorithm.