Preprocessing ordinalencoder transform - 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.
Home › Preprocessing › Encoding and imputation
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,0Remarks — 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.