Skip to content

Commit cfa4868

Browse files
committed
✍🏻 Rename vec_given_feat_val
1 parent aa38ff6 commit cfa4868

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/encoders/contrast_encoder/contrast_encoder.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,18 @@ function contrast_encoder_fit(
123123
throw(ArgumentError("Mode $feat_mode is not supported."))
124124
end
125125

126-
vec_given_feat_val = Dict(level=>contrastmatrix[l, :] for (l, level) in enumerate(feat_levels))
127-
return vec_given_feat_val
126+
vector_given_value_given_feature = Dict(level=>contrastmatrix[l, :] for (l, level) in enumerate(feat_levels))
127+
return vector_given_value_given_feature
128128
end
129129

130130
# 2. Pass it to generic_fit
131-
vec_given_feat_val, encoded_features = generic_fit(
131+
vector_given_value_given_feature, encoded_features = generic_fit(
132132
X, features; ignore = ignore, ordered_factor = ordered_factor,
133133
feature_mapper = feature_mapper,
134134
)
135135

136136
cache = Dict(
137-
:vec_given_feat_val => vec_given_feat_val,
137+
:vector_given_value_given_feature => vector_given_value_given_feature,
138138
:encoded_features => encoded_features,
139139
)
140140

@@ -156,6 +156,6 @@ Use a fitted contrast encoder to encode the levels of selected categorical varia
156156
- `X_tr`: The table with selected features after the selected features are encoded by contrast encoding.
157157
"""
158158
function contrast_encoder_transform(X, cache::Dict)
159-
vec_given_feat_val = cache[:vec_given_feat_val]
160-
return generic_transform(X, vec_given_feat_val, single_feat = false)
159+
vector_given_value_given_feature = cache[:vector_given_value_given_feature]
160+
return generic_transform(X, vector_given_value_given_feature, single_feat = false)
161161
end

src/encoders/contrast_encoder/interface_mlj.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end;
2323

2424
# 4. Fitted parameters (for user access)
2525
MMI.fitted_params(::ContrastEncoder, fitresult) = (
26-
vec_given_feat_val = fitresult,
26+
vector_given_value_given_feature = fitresult,
2727
)
2828

2929
# 5. Fit method
@@ -36,7 +36,7 @@ function MMI.fit(transformer::ContrastEncoder, verbosity::Int, X)
3636
buildmatrix = transformer.buildmatrix,
3737
ordered_factor = transformer.ordered_factor,
3838
)
39-
fitresult = generic_cache[:vec_given_feat_val]
39+
fitresult = generic_cache[:vector_given_value_given_feature]
4040

4141
report = (encoded_features = generic_cache[:encoded_features],) # report only has list of encoded features
4242
cache = nothing
@@ -47,7 +47,7 @@ end;
4747
# 6. Transform method
4848
function MMI.transform(transformer::ContrastEncoder, fitresult, Xnew)
4949
generic_cache = Dict(
50-
:vec_given_feat_val =>
50+
:vector_given_value_given_feature =>
5151
fitresult,
5252
)
5353
Xnew_transf = contrast_encoder_transform(Xnew, generic_cache)
@@ -112,7 +112,7 @@ Only relevant if `mode` is `:contrast` or `:hypothesis`.
112112
113113
The fields of `fitted_params(mach)` are:
114114
115-
- `vec_given_feat_val`: A dictionary that maps each level for each column in a subset of the categorical features of X into its frequency.
115+
- `vector_given_value_given_feature`: A dictionary that maps each level for each column in a subset of the categorical features of X into its frequency.
116116
117117
# Report
118118

test/encoders/contrast_encoder.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ end
5353
contrast_matrix = get_dummy_contrast(k)
5454
print()
5555
for (i, level) in enumerate(levels(X.name))
56-
println(cache[:vec_given_feat_val])
57-
@test cache[:vec_given_feat_val][:name][level] == contrast_matrix[i, :]
56+
println(cache[:vector_given_value_given_feature])
57+
@test cache[:vector_given_value_given_feature][:name][level] == contrast_matrix[i, :]
5858
end
5959
end
6060

@@ -82,7 +82,7 @@ end
8282
k = length(levels(X.favnum))
8383
contrast_matrix = get_sum_contrast(k)
8484
for (i, level) in enumerate(levels(X.favnum))
85-
@test cache[:vec_given_feat_val][:favnum][level] == contrast_matrix[i, :]
85+
@test cache[:vector_given_value_given_feature][:favnum][level] == contrast_matrix[i, :]
8686
end
8787
end
8888

@@ -101,7 +101,7 @@ end
101101
k = length(levels(X.favnum))
102102
contrast_matrix = get_backward_diff_contrast(k)
103103
for (i, level) in enumerate(levels(X.favnum))
104-
@test cache[:vec_given_feat_val][:favnum][level] == contrast_matrix[i, :]
104+
@test cache[:vector_given_value_given_feature][:favnum][level] == contrast_matrix[i, :]
105105
end
106106
end
107107

@@ -118,7 +118,7 @@ end
118118
k = length(levels(X.favnum))
119119
contrast_matrix = get_forward_diff_contrast(k)
120120
for (i, level) in enumerate(levels(X.favnum))
121-
@test cache[:vec_given_feat_val][:favnum][level] == contrast_matrix[i, :]
121+
@test cache[:vector_given_value_given_feature][:favnum][level] == contrast_matrix[i, :]
122122
end
123123
end
124124

@@ -140,7 +140,7 @@ end
140140
k = length(levels(X.name))
141141
contrast_matrix = get_helmert_contrast(k)
142142
for (i, level) in enumerate(levels(X.name))
143-
@test cache[:vec_given_feat_val][:name][level] == contrast_matrix[i, :]
143+
@test cache[:vector_given_value_given_feature][:name][level] == contrast_matrix[i, :]
144144
end
145145
end
146146

@@ -284,8 +284,8 @@ end
284284
@test X_transf == Xnew_transf
285285

286286
# fitted parameters is correct
287-
vec_given_feat_val = fitted_params(mach).vec_given_feat_val
288-
@test vec_given_feat_val == generic_cache[:vec_given_feat_val]
287+
vector_given_value_given_feature = fitted_params(mach).vector_given_value_given_feature
288+
@test vector_given_value_given_feature == generic_cache[:vector_given_value_given_feature]
289289

290290
# Test report
291291
@test report(mach) == (encoded_features = generic_cache[:encoded_features],)

0 commit comments

Comments
 (0)