@@ -14,19 +14,39 @@ env1 = map(e -> [e[1]], env) # just the first row
1414 @test Maxnet. features_from_string (" lqpt" ) == [LinearFeature (), CategoricalFeature (), QuadraticFeature (), ProductFeature (), ThresholdFeature ()]
1515
1616 @test Maxnet. default_features (100 ) == [LinearFeature (), CategoricalFeature (), QuadraticFeature (), HingeFeature (), ProductFeature ()]
17+
18+ @test Maxnet. hinge (1 : 5 , 3 ) == [
19+ # 1:5 3:5 1:3 1:5
20+ 0.0 0.0 0.0 0.0
21+ 0.25 0.0 0.5 0.25
22+ 0.5 0.0 1.0 0.5
23+ 0.75 0.5 1.0 0.75
24+ 1.0 1.0 1.0 1.0
25+ ]
26+ @test size (Maxnet. hinge (1 : 200 )) == (200 , 98 )
27+
28+ presence, predictors = Maxnet. addsamples ([true , false , false ], (a = [1 ,2 ,3 ], b = [1 ,2 ,3 ]))
29+ @test presence == [true , false , false , false ]
30+ @test predictors == (a = [1 ,2 ,3 ,1 ], b = [1 ,2 ,3 ,1 ])
1731end
1832
1933@testset " Maxnet" begin
2034 # some class combinations and keywords
21- m = Maxnet. maxnet (p_a, env; features = " lq" );
22- Maxnet. maxnet (p_a, env; features = " lqp" , regularization_multiplier = 2. );
23- Maxnet. maxnet (p_a, env; features = " lqh" , regularization_multiplier = 5. , nknots = 10 );
24- Maxnet. maxnet (p_a, env; features = " lqph" , weight_factor = 10. );
35+ m = maxnet (p_a, env; features = " lq" );
36+ m2 = maxnet (p_a, env)
37+ m3 = maxnet (p_a, env[(:cld6190_ann , :h_dem )])
38+ m4 = maxnet (p_a, env[(:ecoreg ,)], addsamplestobackground = false )
39+ m5 = maxnet (p_a, env[(:cld6190_ann , :h_dem )]; features = " ht" , n_knots = 3 )
2540
26- # test the result
41+ # test the results
2742 @test m. entropy ≈ 6.114650341746531
2843 @test complexity (m) == 21
29-
44+ @test m2. features == [LinearFeature (), CategoricalFeature (), QuadraticFeature (), HingeFeature (), ProductFeature ()]
45+ @test m3. features == [LinearFeature (), QuadraticFeature (), HingeFeature (), ProductFeature ()]
46+ @test m4. features == [CategoricalFeature ()]
47+ @test m5. features == [HingeFeature (), ThresholdFeature ()]
48+ @test length (m5. columns) == 14 # (n-1)*2 hinge columns and n threshold columns for each variable
49+
3050 # predictions
3151 prediction = predict (m, env)
3252 @test Statistics. mean (prediction[p_a]) > Statistics. mean (prediction[.~ p_a])
5777 using MLJBase
5878 mn = Maxnet. MaxnetBinaryClassifier
5979
80+ # Test model metadata
81+ @test name (mn) == " MaxnetBinaryClassifier"
82+ @test human_name (mn) == " Maxnet"
83+ @test package_name (mn) == " Maxnet"
84+ @test ! supports_weights (mn)
85+ @test ! is_pure_julia (mn)
86+ @test is_supervised (mn)
87+ @test package_license (mn) == " MIT"
88+ @test prediction_type (mn) == :probabilistic
89+ @test input_scitype (mn) == Table{<: Union{AbstractVector{<:Continuous}, AbstractVector{<:Finite}} }
90+ @test hyperparameters (mn) == (:features , :regularization_multiplier , :regularization_function , :weight_factor , :link , :clamp , :kw )
91+
6092 # convert to continuous
6193 cont_keys = collect (key => Continuous for key in keys (env) if key != = :ecoreg )
6294 env_typed = MLJBase. coerce (env, cont_keys... )
71103 # make the equivalent model without mlj
72104 model = Maxnet. maxnet ((p_a), env_typed; features = " lqph" );
73105
74-
75106 # predict via MLJBase
76107 mljprediction = MLJBase. predict (mach2, env_typed)
77108 mlj_true_probability = pdf .(mljprediction, true )
0 commit comments