Skip to content

Preprocessing 0.2.0 labelencoder 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.

Home › Encoding and imputation

LabelEncoder.Transform

Reads labels as codes.

public int[] Transform(ReadOnlySpan<T> labels)

Parameters — labels is one column of labels to encode.

Returns — one code per label: its index in Classes.

Exceptions — ArgumentException when labels holds a null, or a label this encoder was not fitted on.

Example — the fitted column, and one value on its own.

using Lodestar.Preprocessing;

string[] cities = ["paris", "lyon", "paris", "nice"];

LabelEncoder<string> encoder = Encoders.Label<string>(cities);

string all = string.Join(",", encoder.Transform(cities));      // => 2,0,2,1
int one = encoder.Transform(["nice"])[0];                      // => 1

Remarks — an unseen label is refused, and there is no option to encode it anyway. The reference refuses it too, and here that is the only reasonable answer: a target column's codes name classes, and a class nobody fitted has no code that means anything. That is the difference from OneHotEncoder, which offers UnknownCategory.Zeros because a feature can legitimately meet a value the training set did not.

Applies to — net10.0, netstandard2.0.

See also — LabelEncoder.InverseTransform, LabelEncoder.

Clone this wiki locally