Skip to content

Preprocessing 0.2.0 labelencoder

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

Gives each distinct label a code, at sklearn.preprocessing.LabelEncoder parity.

public sealed class LabelEncoder<T> where T : IComparable<T>, IEquatable<T>

Type parameter — T is the label type; string and int are the two the reference takes.

Properties — SampleCount is how many labels it was fitted on. Classes is the distinct labels in sorted order — the reference's classes_ — and the code of a label is its index here.

Example — four rows, three cities.

using Lodestar.Preprocessing;

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

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

string classes = string.Join(",", encoder.Classes);            // => lyon,nice,paris
string codes = string.Join(",", encoder.Transform(cities));    // => 2,0,2,1

Remarks — this is for the target column, not for the features. It takes one column and the reference says so in as many words; a feature matrix goes through OrdinalEncoder, which is the same idea over several columns at once and returns doubles rather than indices. The distinction is worth keeping because the two have different jobs downstream: a target's codes are class labels a classifier reports back, and a feature's codes are values a model computes with.

The order is the sort order of T, so strings sort by code point as numpy's do and integers as numbers. It is not the order of first appearance, which is what makes the codes reproducible across a reordered file.

There is no Fit on this type: Encoders.Label is the factory, for the reason Encoders states.

Applies to — net10.0, netstandard2.0.

See also — Encoders.Label, OrdinalEncoder, the encoding index, the Python equivalence table.

Members

Member What it does
LabelEncoder.InverseTransform Reads codes back as labels.
LabelEncoder.Transform Reads labels as codes.

Clone this wiki locally