@@ -10,16 +10,34 @@ using Distributions: Binomial
1010const SLM = StatsLearnModels
1111
1212@testset " StatsLearnModels.jl" begin
13- @testset " Basic" begin
14- # show method
15- x1 = rand (1 : 0.1 : 10 , 100 )
16- x2 = rand (1 : 0.1 : 10 , 100 )
17- y = 2 x1 + x2
18- input = DataFrame (; x1, x2)
19- output = DataFrame (; y)
20- model = DecisionTreeClassifier ()
21- fmodel = SLM. fit (model, input, output)
22- @test sprint (show, fmodel) == " FittedStatsLearnModel{DecisionTreeClassifier}"
13+ @testset " LabeledTable" begin
14+ # labels as symbols
15+ t = (x1= rand (3 ), x2= rand (3 ), y= rand (Int, 3 ))
16+ l = label (t, :y )
17+ @test parent (l) == t
18+ @test predictors (l) == [:x1 , :x2 ]
19+ @test targets (l) == [:y ]
20+
21+ # labels as strings
22+ t = (x1= rand (3 ), x2= rand (3 ), y= rand (Int, 3 ))
23+ l = label (t, " y" )
24+ @test parent (l) == t
25+ @test predictors (l) == [:x1 , :x2 ]
26+ @test targets (l) == [:y ]
27+
28+ # multiple labels
29+ t = (x1= rand (3 ), x2= rand (3 ), y1= rand (Int, 3 ), y2= rand (Int, 3 ))
30+ l = label (t, [" y1" , " y2" ])
31+ @test parent (l) == t
32+ @test predictors (l) == [:x1 , :x2 ]
33+ @test targets (l) == [:y1 , :y2 ]
34+
35+ # labels as regex
36+ t = (x1= rand (3 ), x2= rand (3 ), y1= rand (Int, 3 ), y2= rand (Int, 3 ))
37+ l = label (t, r" y" )
38+ @test parent (l) == t
39+ @test predictors (l) == [:x1 , :x2 ]
40+ @test targets (l) == [:y1 , :y2 ]
2341 end
2442
2543 @testset " Models" begin
@@ -77,6 +95,16 @@ const SLM = StatsLearnModels
7795 accuracy = count (foutput. y .== output. y) / length (output. y)
7896 @test accuracy > 0
7997 end
98+
99+ # show method
100+ x1 = rand (1 : 0.1 : 10 , 100 )
101+ x2 = rand (1 : 0.1 : 10 , 100 )
102+ y = 2 x1 + x2
103+ input = DataFrame (; x1, x2)
104+ output = DataFrame (; y)
105+ model = DecisionTreeClassifier ()
106+ fmodel = SLM. fit (model, input, output)
107+ @test sprint (show, fmodel) == " FittedStatsLearnModel{DecisionTreeClassifier}"
80108 end
81109
82110 @testset " Learn" begin
0 commit comments