1010 ytest = selectrows (y, test)
1111
1212 lda_model = LDA ()
13-
13+
1414 # # Check model `fit`
1515 fitresult, = fit (lda_model, 1 , Xtrain, ytrain)
1616 class_means, projection_matrix = fitted_params (lda_model, fitresult)
2828 tlda_mlj = transform (lda_model, fitresult, X)
2929 @test tlda_mlj == tlda_ms
3030 # # Check model traits
31- d = info_dict (LDA)
32- @test d[:input_scitype ] == Table (Continuous)
33- @test d[:target_scitype ] == AbstractVector{<: Finite }
34- @test d[:name ] == " LDA"
3531end
3632
3733@testset " MLDA-2" begin
5551 ytrain = selectrows (y, train)
5652 Xtest = selectrows (X, test)
5753 ytest = selectrows (y, test)
58-
54+
5955 lda_model = LDA ()
6056 # # Check model `fit`/`predict`
6157 fitresult, = fit (lda_model, 1 , Xtrain, ytrain)
7470 ytrain = selectrows (y, train)
7571 Xtest = selectrows (X, test)
7672 ytest = selectrows (y, test)
77-
73+
7874 BLDA_model = BayesianLDA ()
7975 # # Check model `fit`
8076 fitresult, = fit (BLDA_model, 1 , Xtrain, ytrain)
8581 mce = cross_entropy (preds, ytest) |> mean
8682 @test 0.685 ≤ mce ≤ 0.695
8783 # # Check model traits
88- d = info_dict (BayesianLDA)
89- @test d[:input_scitype ] == Table (Continuous)
90- @test d[:target_scitype ] == AbstractVector{<: Finite }
91- @test d[:name ] == " BayesianLDA"
9284end
9385
9486@testset " BayesianSubspaceLDA" begin
95- # # Data
87+ # # Data
9688 X, y = @load_iris
9789 LDA_model = BayesianSubspaceLDA ()
9890 # # Check model `fit`
@@ -113,27 +105,23 @@ end
113105 abs .(
114106 projection_matrix ≈ [
115107 0.0675721 0.00271023 ;
116- 0.127666 0.177718 ;
117- - 0.180211 - 0.0767255 ;
108+ 0.127666 0.177718 ;
109+ - 0.180211 - 0.0767255 ;
118110 - 0.235382 0.231435
119111 ]
120112 )
121113 ) < 0.05
122114 @test round .(prior_probabilities, sigdigits= 7 ) == [0.3333333 , 0.3333333 , 0.3333333 ]
123115 @test round .(report. explained_variance_ratio, digits= 4 ) == [0.9915 , 0.0085 ]
124-
116+
125117 # # Check model `predict`
126118 preds= predict (LDA_model, fitresult, X)
127119 predicted_class = predict_mode (LDA_model, fitresult, X)
128120 mcr = misclassification_rate (predicted_class, y)
129121 mce = cross_entropy (preds, y) |> mean
130- @test round .(mcr, sigdigits= 1 ) == 0.02
122+ @test round .(mcr, sigdigits= 1 ) == 0.02
131123 @test 0.04 ≤ mce ≤ 0.045
132124 # # Check model traits
133- d = info_dict (BayesianSubspaceLDA)
134- @test d[:input_scitype ] == Table (Continuous)
135- @test d[:target_scitype ] == AbstractVector{<: Finite }
136- @test d[:name ] == " BayesianSubspaceLDA"
137125end
138126
139127@testset " SubspaceLDA" begin
157145 ytrain = selectrows (y, train)
158146 Xtest = selectrows (X, test)
159147 ytest = selectrows (y, test)
160-
148+
161149 lda_model = SubspaceLDA ()
162150 # # Check model `fit`/ `transform`
163151 fitresult, = fit (lda_model, 1 , Xtrain, ytrain)
174162 tlda_mlj = transform (lda_model, fitresult, X)
175163 @test tlda_mlj == tlda_ms
176164 # # Check model traits
177- d = info_dict (SubspaceLDA)
178- @test d[:input_scitype ] == Table (Continuous)
179- @test d[:target_scitype ] == AbstractVector{<: Finite }
180- @test d[:name ] == " SubspaceLDA"
181165end
182166
183167@testset " discriminant models checks" begin
@@ -187,7 +171,7 @@ X = (x1 =rand(4), x2 = collect(1:4))
187171
188172# # Note: The following test depend on the order in which they are written.
189173# # Hence do not change the ordering of the tests.
190-
174+
191175# # Check to make sure error is thrown if we only have a single
192176# # unique class during training.
193177model = LDA ()
@@ -199,23 +183,23 @@ y1 = y[[1,1,1,1]]
199183# # than unique classes during training.
200184@test_throws ArgumentError fit (model, 1 , X, y)
201185
202- # # Check to make sure error is thrown if `out_dim` exceeds the number of features in
186+ # # Check to make sure error is thrown if `out_dim` exceeds the number of features in
203187# # sample matrix used in training.
204188model = LDA (out_dim= 3 )
205189# categorical array with same pool as y but only containing "apples" & "oranges"
206- y2 = y[[1 ,2 ,1 ,2 ]]
190+ y2 = y[[1 ,2 ,1 ,2 ]]
207191@test_throws ArgumentError fit (model, 1 , X, y2)
208192
209- # # Check to make sure error is thrown if length(`priors`) != number of classes
193+ # # Check to make sure error is thrown if length(`priors`) != number of classes
210194# # in common pool of target vector used in training.
211195model = BayesianLDA (priors= [0.1 , 0.5 , 0.4 ])
212196@test_throws ArgumentError fit (model, 1 , X, y)
213197
214- # # Check to make sure error is thrown if sum(`priors`) isn't approximately equal to 1.
198+ # # Check to make sure error is thrown if sum(`priors`) isn't approximately equal to 1.
215199model = BayesianLDA (priors= [0.1 , 0.5 , 0.4 , 0.2 ])
216200@test_throws ArgumentError fit (model, 1 , X, y)
217201
218- # # Check to make sure error is thrown if `priors .< 0` or `priors .> 1`.
202+ # # Check to make sure error is thrown if `priors .< 0` or `priors .> 1`.
219203model = BayesianLDA (priors= [- 0.1 , 0.0 , 1.0 , 0.1 ])
220204@test_throws ArgumentError fit (model, 1 , X, y)
221205model = BayesianLDA (priors= [1.1 , 0.0 , 0.0 , - 0.1 ])
0 commit comments