Preprocessing ordinalencoder - CyrilB1531/lodestar GitHub Wiki

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

OrdinalEncoder

One code per category, at sklearn.preprocessing.OrdinalEncoder parity.

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

Type parametersT is the category type; string and int are the two the reference takes.

PropertiesFeatureCount and SampleCount are the shape it was fitted on, and Categories is each feature's categories, sorted. The code of a value is its index in that list.

Example — the codes carry the sort order.

using Lodestar.Preprocessing;

OrdinalEncoder<string> encoder = Encoders.Ordinal(["b", "a", "c"], featureCount: 1);

string categories = string.Join(",", encoder.Categories[0]);      // => a,b,c
string codes = string.Join(",", encoder.Transform(["c", "a"]));   // => 2,0

Remarksone column in, one column out, where OneHotEncoder gives each category a column of its own. That makes it the cheaper encoding and the more dangerous one: the codes are numbers, so a model that reads them as numbers reads the sort order as distance — 'c' is twice 'b', which nothing in the data said.

Applies to — net10.0, netstandard2.0.

See alsoEncoders.Ordinal, OneHotEncoder.

Members

Member What it does
OrdinalEncoder.Transform Encodes a matrix as category indices.
⚠️ **GitHub.com Fallback** ⚠️