Skip to content

Preprocessing 0.2.0 onehotencoder transform

github-actions[bot] edited this page Sep 24, 2026 · 1 revision

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.

HomeEncoding and imputation

OneHotEncoder.Transform

Encodes a row-major matrix of categories.

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

Parametersvalues is the categories to encode, row-major, with FeatureCount per row.

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

ExceptionsArgumentException when values holds no row, a partial one, or a null; or when it holds a category the fit never saw and the encoder was fitted with UnknownCategory.Refuse.

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

Remarksa 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 alsoOneHotEncoder, OneHotEncoderOptions.

Clone this wiki locally