Preprocessing 0.2.0 ordinalencoder transform - CyrilB1531/lodestar GitHub Wiki

Lodestar.Preprocessing 0.2.0. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

Home › Encoding and imputation

OrdinalEncoder.Transform

Encodes a row-major matrix as category indices.

public double[] Transform(ReadOnlySpan<T> values)

Parameters — values is the categories to encode, row-major, with FeatureCount per row.

Returns — a new array of the same length, each value the index of its category.

Exceptions — ArgumentException when values holds no row, a partial one, a null, or a category the fit never saw.

Example — two features, each coded against its own categories.

using Lodestar.Preprocessing;

string[] values = ["b", "x", "a", "y", "c", "x"];

OrdinalEncoder<string> encoder = Encoders.Ordinal(values, featureCount: 2);

string codes = string.Join(",", encoder.Transform(values));  // => 1,0,0,1,2,0

Remarks — an unseen category is refused rather than coded: the reference's default raises too, and its use_encoded_value needs a value outside the codes that nothing here asks for yet.

Returns double[] rather than int[] so the result feeds a scaler or a model without a conversion.

Applies to — net10.0, netstandard2.0.

See also — OrdinalEncoder, Encoders.Ordinal.

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