-
Notifications
You must be signed in to change notification settings - Fork 0
Preprocessing labelencoder
Development build. This page describes
main, not a released package. The latest published Lodestar.Preprocessing is 0.1.0 — read its documentation.
Home › Preprocessing › Encoding and imputation
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,1Remarks — 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.
| Member | What it does |
|---|---|
LabelEncoder.InverseTransform |
Reads codes back as labels. |
LabelEncoder.Transform |
Reads labels as codes. |