Skip to content

Preprocessing onehotencoder

github-actions[bot] edited this page Sep 21, 2026 · 11 revisions

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

OneHotEncoder

One column per category, at sklearn.preprocessing.OneHotEncoder parity.

public sealed class OneHotEncoder<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. EncodedFeatureCount is how many columns Transform produces, which is fewer than the total number of categories when one is dropped. Categories is each feature's categories, sorted — the reference's categories_.

Example — a fitted encoder reports what it will produce before it produces it.

using Lodestar.Preprocessing;

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

int rows = encoder.SampleCount;          // => 4
int columns = encoder.EncodedFeatureCount; // => 3

Remarks — fitted through Encoders.OneHot rather than a static Fit here: a public static on a generic type is what CA1000 refuses, and the factory infers T.

Applies to — net10.0, netstandard2.0.

See alsoOneHotEncoderOptions, OrdinalEncoder.

Members

Member What it does
OneHotEncoder.Transform Encodes a matrix as one column per category.

Clone this wiki locally