Preprocessing onehotencoderoptions - 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
Which category OneHotEncoder drops, and what it does with an unseen value.
public sealed record OneHotEncoderOptionsProperties — Drop chooses which category loses its column, and Unknown what happens to a
value the fit never saw — sklearn.preprocessing.OneHotEncoder's drop and handle_unknown, same
defaults. MinFrequency makes a category seen fewer times infrequent, and MinFrequencyShare one
seen in fewer than that share of the rows, strictly between 0 and 1: min_frequency as an integer
and as a float, one setting, so the two are refused together. MaxCategories caps each feature's
columns, its infrequent one included — max_categories. All three are null by default, which
groups nothing.
Example — IfBinary drops the first category only where the feature has exactly two.
using Lodestar.Preprocessing;
var options = new OneHotEncoderOptions { Drop = CategoryDrop.IfBinary };
OneHotEncoder<string> binary = Encoders.OneHot(["y", "n", "y"], 1, options);
OneHotEncoder<string> three = Encoders.OneHot(["a", "b", "c"], 1, options);
int binaryColumns = binary.EncodedFeatureCount; // => 1
int threeColumns = three.EncodedFeatureCount; // => 3Example — at most two columns: the most frequent category, and one for the rest.
using Lodestar.Preprocessing;
var capped = new OneHotEncoderOptions { MaxCategories = 2 };
OneHotEncoder<string> encoder = Encoders.OneHot(["a", "a", "a", "b", "b", "c", "d"], 1, capped);
int columns = encoder.EncodedFeatureCount; // => 2
string grouped = string.Join(",", encoder.InfrequentCategories[0]!); // => b,c,dRemarks — past MaxCategories the least frequent categories join the infrequent ones, ranked
by a stable sort of the counts, so a tie keeps the sorted category order, as the reference's does.
CategoryDrop.First drops the first column after grouping, and CategoryDrop.IfBinary counts
the grouped columns. The drop and unknown settings interact: an ignored unknown encodes to all zeros, and so does a
dropped first category, so a row of zeros means either. Transform
says so with the example.
Applies to — net10.0, netstandard2.0.
See also — CategoryDrop, UnknownCategory.
| Member | What it does |
|---|---|
OneHotEncoderOptions.GetHashCode |
A hash consistent with the equality, every NaN alike. |