Preprocessing onehotencoder - 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

OneHotEncoder

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

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

Type parameters — T is the category type; string and int are the two the reference takes.

Properties — FeatureCount 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 or several are grouped. Categories is each feature's categories, sorted — the reference's categories_. InfrequentCategories is each feature's infrequent ones, sorted, or null for a feature with none — infrequent_categories_; they share the last column of their feature's block.

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 also — OneHotEncoderOptions, OrdinalEncoder.

Members

Member What it does
OneHotEncoder.Transform Encodes a matrix as one column per category.
OneHotEncoder.TransformSparse The same encoding as a CsrMatrix, the reference's default output.
OneHotEncoder.FeatureNames Each output column's name, get_feature_names_out.
⚠️ **GitHub.com Fallback** ⚠️