11
22@testset " group_inds and get_majority_minority_inds_counts" begin
33 y = [0 , 0 , 0 , 0 , 1 , 1 , 1 , 0 ]
4- @test MLJBalancing. group_inds(y) == Dict(0 => [1 , 2 , 3 , 4 , 8 ], 1 => [5 , 6 , 7 ])
4+ @test MLJBalancing. group_inds(y) == Dict(0 => [1 , 2 , 3 , 4 , 8 ], 1 => [5 , 6 , 7 ])
55 @test MLJBalancing. get_majority_minority_inds_counts(y) ==
66 ([1 , 2 , 3 , 4 , 8 ], [5 , 6 , 7 ], 5 , 3 )
77 y = [0 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 2 , 2 , 2 ]
1818 num_vals_per_category = [3 , 2 , 1 , 2 ],
1919 class_probs = [0.9 , 0.1 ],
2020 type = " ColTable" ,
21- rng = 42 ,
21+ rng = Random . MersenneTwister( 42 ) ,
2222 )
2323 majority_inds, minority_inds, majority_count, minority_count =
2424 MLJBalancing. get_majority_minority_inds_counts(y)
3030 minority_inds,
3131 majority_count,
3232 minority_count,
33- Random. Xoshiro (42 )
33+ Random. MersenneTwister (42 )
3434 )
3535 X_sub, y_sub = X_sub(rows = 1 : 100 ), y_sub(rows = 1 : 100 )
3636 majority_inds_sub, minority_inds_sub, _, _ =
5151
5252@testset " End-to-end Test" begin
5353 # # setup parameters
54- R = Random. Xoshiro (42 )
54+ R = Random. MersenneTwister (42 )
5555 T = 2
5656 LogisticClassifier = @load LogisticClassifier pkg = MLJLinearModels verbosity = 0
5757 model = LogisticClassifier()
6464 num_vals_per_category = [3 , 2 , 1 , 2 ],
6565 class_probs = [0.9 , 0.1 ],
6666 type = " ColTable" ,
67- rng = 42 ,
67+ rng = Random . MersenneTwister( 42 ) ,
6868 )
6969 # testing
7070 Xt, yt = generate_imbalanced_data(
7373 num_vals_per_category = [3 , 2 , 1 , 2 ],
7474 class_probs = [0.9 , 0.1 ],
7575 type = " ColTable" ,
76- rng = 42 ,
76+ rng = Random . MersenneTwister( 42 ) ,
7777 )
7878
7979 # # prepare subsets
@@ -111,14 +111,30 @@ end
111111 pred_manual = mean([pred1, pred2])
112112
113113 # # using BalancedBagging
114- modelo = BalancedBaggingClassifier(model = model, T = 2 , rng = Random. Xoshiro (42 ))
114+ modelo = BalancedBaggingClassifier(model = model, T = 2 , rng = Random. MersenneTwister (42 ))
115115 mach = machine(modelo, X, y)
116116 fit!(mach)
117117 pred_auto = MLJBase. predict(mach, Xt)
118118 @test sum(pred_manual) ≈ sum(pred_auto)
119- modelo = BalancedBaggingClassifier(model = model, rng = Random. Xoshiro (42 ))
119+ modelo = BalancedBaggingClassifier(model = model, rng = Random. MersenneTwister (42 ))
120120 mach = machine(modelo, X, y)
121121 fit!(mach)
122- @test report(mach) == (chosen_T = 5 ,)
123-
122+ @test report(mach) == (chosen_T = 9 ,)
124123end
124+
125+
126+
127+
128+ @testset " Equivalence of Constructions" begin
129+ # # setup parameters
130+ R = Random. MersenneTwister(42 )
131+ T = 2
132+ LogisticClassifier = @load LogisticClassifier pkg = MLJLinearModels verbosity = 0
133+ model = LogisticClassifier()
134+ BalancedBaggingClassifier(model= model, T= T, rng= R) == BalancedBaggingClassifier(model; T= T, rng= R)
135+
136+ @test_throws MLJBalancing. ERR_NUM_ARGS_BB BalancedBaggingClassifier(model, model; T= T, rng= R)
137+ @test_logs (:warn, MLJBalancing. WRN_MODEL_GIVEN) begin
138+ BalancedBaggingClassifier(model; model= model, T= T, rng= R)
139+ end
140+ end
0 commit comments