Preprocessing encoders label - CyrilB1531/lodestar GitHub Wiki
Development build. This page describes
main, not a released package. The latest published Lodestar.Preprocessing is 0.2.0 — read its documentation.
Home › Preprocessing › Encoding and imputation
Fits a label encoder on one column of labels.
public static LabelEncoder<T> Label<T>(ReadOnlySpan<T> labels) where T : IComparable<T>, IEquatable<T>Type parameter — T is the label type; string and int are the two the reference takes.
Parameters — labels is one column of labels.
Returns — a fitted LabelEncoder. Its classes are sorted.
The order is numpy's: a string sorts by code point, not by UTF-16 unit
(#1254), and a floating NaN sorts last (#1229).
Exceptions — ArgumentException when labels is empty or holds a null.
Example — the codes and how many rows were read.
using Lodestar.Preprocessing;
string[] cities = ["paris", "lyon", "paris", "nice"];
LabelEncoder<string> encoder = Encoders.Label<string>(cities);
int rows = encoder.SampleCount; // => 4
string classes = string.Join(",", encoder.Classes); // => lyon,nice,parisRemarks — one column, not a matrix, which is the one difference from
Encoders.Ordinal: the reference's LabelEncoder takes a 1-D array and
its OrdinalEncoder a 2-D one, because the first is for a target and the second for features.
There is no featureCount parameter here for that reason.
Applies to — net10.0, netstandard2.0.
See also — LabelEncoder, Encoders,
Encoders.Ordinal.