Preprocessing ordinalencoder transform - CyrilB1531/lodestar GitHub Wiki
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; a fitted NaN
category is coded NaN, the reference's default encoded_missing_value, and sorts last, so the
other codes are the ones the reference reports (#1229).
Exceptions — ArgumentException when values holds no row, a partial one, a null, an infinite
floating category (#1229), 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.