Skip to content

Commit aa38ff6

Browse files
committed
🔼 Change feat_levels to col_name
1 parent c418bad commit aa38ff6

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/encoders/contrast_encoder/contrast_encoder.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Fit a contrast encoing scheme on given data in `X`.
6565
- `mode=:dummy`: The type of encoding to use. Can be one of `:contrast`, `:dummy`, `:sum`, `:backward_diff`, `:forward_diff`, `:helmert` or `:hypothesis`.
6666
If `ignore=false` (features to be encoded are listed explictly in `features`), then this can be a vector of the same length as `features` to specify a different
6767
contrast encoding scheme for each feature
68-
- `buildmatrix=nothing`: A function that takes a vector of levels and the number of levels as input and should return a contrast or hypothesis matrix.
68+
- `buildmatrix=nothing`: A function that should take column name as a symbol and the number of levels as input and return a contrast or hypothesis matrix.
6969
Only relevant if `mode` is `:contrast` or `:hypothesis`.
7070
- `ignore=true`: Whether to exclude or includes the features given in `features`
7171
- `ordered_factor=false`: Whether to encode `OrderedFactor` or ignore them
@@ -103,10 +103,10 @@ function contrast_encoder_fit(
103103
k = length(feat_levels)
104104
feat_mode = (mode_is_vector) ? mode[findfirst(isequal(name), features)] : mode
105105
if feat_mode == :contrast
106-
contrastmatrix = buildmatrix(feat_levels, k)
106+
contrastmatrix = buildmatrix(name, k)
107107
size(contrastmatrix) == (k, k-1) || throw(ArgumentError(MATRIX_SIZE_ERROR(k, size(contrastmatrix), name)))
108108
elseif feat_mode == :hypothesis
109-
hypothesismatrix = buildmatrix(feat_levels, k)
109+
hypothesismatrix = buildmatrix(name, k)
110110
size(hypothesismatrix) == (k-1, k) || throw(ArgumentError(MATRIX_SIZE_ERROR_HYP(k, size(hypothesismatrix), name)))
111111
contrastmatrix = pinv(hypothesismatrix)
112112
elseif feat_mode == :dummy

test/encoders/contrast_encoder.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ age = [23, 23, 14, 23])
1111
@testset "Contrast Encoder Error Handling" begin
1212

1313
# Example definitions to allow the test to run
14-
function dummy_buildmatrix(levels, k)
14+
function dummy_buildmatrix(colname, k)
1515
# Simple dummy function to generate a matrix of correct size
1616
return randn(k, k-1) # Adjust dimensions as needed for the test
1717
end
@@ -149,7 +149,7 @@ end
149149
@testset "contrast mode end-to-end test" begin
150150

151151

152-
function buildrandomcontrast(feat_levels, k)
152+
function buildrandomcontrast(colname, k)
153153
return rand(StableRNGs.StableRNG(123), k, k-1)
154154
end
155155

@@ -174,7 +174,7 @@ end
174174
# @testset "hypothesis matrix end-to-end test"
175175
@testset "hypothesis mode end-to-end test" begin
176176

177-
function buildrandomhypothesis(feat_levels, k)
177+
function buildrandomhypothesis(colname, k)
178178
return rand(StableRNGs.StableRNG(123), k-1, k)
179179
end
180180

@@ -194,11 +194,11 @@ end
194194
end
195195

196196

197-
function buildrandomhypothesis(feat_levels, k)
197+
function buildrandomhypothesis(colname, k)
198198
return rand(StableRNGs.StableRNG(123), k-1, k)
199199
end
200200

201-
function buildrandomcontrast(feat_levels, k)
201+
function buildrandomcontrast(colname, k)
202202
return rand(StableRNGs.StableRNG(123), k, k-1)
203203
end
204204

0 commit comments

Comments
 (0)