Skip to content

Preprocessing labelencoder transform

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

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

HomePreprocessingEncoding and imputation

LabelEncoder.Transform

Reads labels as codes.

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

Parameterslabels is one column of labels to encode.

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

ExceptionsArgumentException 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 alsoLabelEncoder.InverseTransform, LabelEncoder.

Clone this wiki locally