Preprocessing simpleimputer fit - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Preprocessing is 0.1.0 — read its documentation.

HomePreprocessingEncoding and imputation

SimpleImputer.Fit

Fits an imputer on a row-major sample matrix.

public static SimpleImputer Fit(ReadOnlySpan<double> samples, int featureCount, SimpleImputerOptions options = null)

Parameterssamples is the sample matrix, row-major: featureCount values per row, NaN where a value is missing. featureCount is how many values each row carries. options chooses the statistic; null is the mean.

Returns — a fitted SimpleImputer.

ExceptionsArgumentOutOfRangeException when featureCount is not positive, the fill value is not finite, or the strategy is not a defined value. ArgumentException when samples holds no row, a partial one, or an infinity; or when a feature has no value at all and KeepEmptyFeatures is not set.

Example — the median of an even count is the average of the two middle values.

using Lodestar.Preprocessing;

double[] samples = [1.0, 2.0, 3.0, 4.0, double.NaN];

SimpleImputer imputer = SimpleImputer.Fit(
    samples, 1, new SimpleImputerOptions { Strategy = ImputationStrategy.Median });

double median = imputer.Statistics[0];  // => 2.5

Remarksa feature with nothing in it is refused, where the reference drops it and returns a matrix one column narrower than the one it was given. That is this package's one divergence here, and it is deliberate: a transform whose output width depends on the fitted data rather than on the input shape is a trap in a typed API. Set SimpleImputerOptions.KeepEmptyFeatures to fill such a feature instead, which is the reference's keep_empty_features=True: with zero, or with FillValue under ImputationStrategy.Constant.

Applies to — net10.0, netstandard2.0.

See alsoSimpleImputer, ImputationStrategy.

⚠️ **GitHub.com Fallback** ⚠️