Preprocessing onehotencoder transform - CyrilB1531/lodestar GitHub Wiki

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

Home › Preprocessing › Encoding and imputation

OneHotEncoder.Transform

Encodes a row-major matrix of categories.

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

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

Returns — a new array of rows × EncodedFeatureCount values, each 0 or 1.

Exceptions — ArgumentException when values holds no row, a partial one, a null, or an infinite floating category (#1229); or when it holds a category the fit never saw and the encoder was fitted with UnknownCategory.Refuse. ArgumentException also when the rows times the encoded width are more cells than one array holds (#1314).

Example — an ignored unknown and a dropped first category produce the same row.

using Lodestar.Preprocessing;

var options = new OneHotEncoderOptions
{
    Drop = CategoryDrop.First,
    Unknown = UnknownCategory.Ignore,
};

OneHotEncoder<string> encoder = Encoders.OneHot(["a", "b", "c"], 1, options);

string dropped = string.Join(",", encoder.Transform(["a"]));      // => 0,0
string unknown = string.Join(",", encoder.Transform(["zzz"]));    // => 0,0

Remarks — a row of zeros means either, and nothing distinguishes them. That collision is the reference's, not this package's invention, and it is the reason to think twice before combining the two options.

Applies to — net10.0, netstandard2.0.

See also — OneHotEncoder, OneHotEncoderOptions.

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