@@ -11,6 +11,7 @@ Fit an encoder to encode the levels of categorical variables in a given table as
1111 - `ignore=true`: Whether to exclude or includes the features given in `features`
1212 - `ordered_factor=false`: Whether to encode `OrderedFactor` or ignore them
1313 - `dtype`: The numerical concrete type of the encoded features. Default is `Float32`.
14+
1415# Returns (in a dict)
1516
1617 - `index_given_feat_level`: Maps each level for each column in a subset of the categorical features of X into an integer.
@@ -27,18 +28,19 @@ function ordinal_encoder_fit(
2728 function feature_mapper (col, name)
2829 feat_levels = levels (col)
2930 index_given_feat_val =
30- Dict {eltype(feat_levels), output_type} (value => index for (index, value) in enumerate (feat_levels))
31+ Dict {eltype(feat_levels), output_type} (
32+ value => index for (index, value) in enumerate (feat_levels)
33+ )
3134 return index_given_feat_val
3235 end
3336
3437 # 2. Pass it to generic_fit
3538 index_given_feat_level, encoded_features = generic_fit (
3639 X, features; ignore = ignore, ordered_factor = ordered_factor,
37- feature_mapper = feature_mapper,
38- )
39- cache = Dict (
40- :index_given_feat_level => index_given_feat_level,
41- :encoded_features => encoded_features,
40+ feature_mapper = feature_mapper,)
41+ cache = (
42+ index_given_feat_level = index_given_feat_level,
43+ encoded_features = encoded_features,
4244 )
4345 return cache
4446end
@@ -58,7 +60,7 @@ Encode the levels of a categorical variable in a given table as integers.
5860
5961 - `X_tr`: The table with selected features after the selected features are encoded by ordinal encoding.
6062"""
61- function ordinal_encoder_transform (X, cache:: Dict )
62- index_given_feat_level = cache[ : index_given_feat_level]
63+ function ordinal_encoder_transform (X, cache:: NamedTuple )
64+ index_given_feat_level = cache. index_given_feat_level
6365 return generic_transform (X, index_given_feat_level)
6466end
0 commit comments