@@ -11,6 +11,7 @@ Fit an encoder to encode the levels of categorical variables in a given table as
11
11
- `ignore=true`: Whether to exclude or includes the features given in `features`
12
12
- `ordered_factor=false`: Whether to encode `OrderedFactor` or ignore them
13
13
- `dtype`: The numerical concrete type of the encoded features. Default is `Float32`.
14
+
14
15
# Returns (in a dict)
15
16
16
17
- `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(
27
28
function feature_mapper (col, name)
28
29
feat_levels = levels (col)
29
30
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
+ )
31
34
return index_given_feat_val
32
35
end
33
36
34
37
# 2. Pass it to generic_fit
35
38
index_given_feat_level, encoded_features = generic_fit (
36
39
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,
42
44
)
43
45
return cache
44
46
end
@@ -58,7 +60,7 @@ Encode the levels of a categorical variable in a given table as integers.
58
60
59
61
- `X_tr`: The table with selected features after the selected features are encoded by ordinal encoding.
60
62
"""
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
63
65
return generic_transform (X, index_given_feat_level)
64
66
end
0 commit comments