69
69
# This a variation of `Selector` above that stores the names of rejected features in the
70
70
# output of `fit`, for inspection by an accessor function called `rejected`.
71
71
72
- struct Selector2
72
+ struct FancySelector
73
73
names:: Vector{Symbol}
74
74
end
75
- Selector2 (; names= Symbol[]) = Selector2 (names) # LearnAPI.constructor defined later
75
+ FancySelector (; names= Symbol[]) = FancySelector (names) # LearnAPI.constructor defined later
76
76
77
- mutable struct Selector2Fit
78
- algorithm:: Selector2
77
+ mutable struct FancySelectorFitted
78
+ algorithm:: FancySelector
79
79
rejected:: Vector{Symbol}
80
- Selector2Fit (algorithm) = new (algorithm)
80
+ FancySelectorFitted (algorithm) = new (algorithm)
81
81
end
82
- LearnAPI. algorithm (model:: Selector2Fit ) = model. algorithm
83
- rejected (model:: Selector2Fit ) = model. rejected
82
+ LearnAPI. algorithm (model:: FancySelectorFitted ) = model. algorithm
83
+ rejected (model:: FancySelectorFitted ) = model. rejected
84
84
85
85
# Here we are wrapping `algorithm` with a place-holder for the `rejected` feature names.
86
- LearnAPI. fit (algorithm:: Selector2 ; verbosity= 1 ) = Selector2Fit (algorithm)
86
+ LearnAPI. fit (algorithm:: FancySelector ; verbosity= 1 ) = FancySelectorFitted (algorithm)
87
87
88
88
# output the filtered table and add `rejected` field to model (mutatated!)
89
- function LearnAPI. transform (model:: Selector2Fit , X)
89
+ function LearnAPI. transform (model:: FancySelectorFitted , X)
90
90
table = Tables. columntable (X)
91
91
names = Tables. columnnames (table)
92
92
keep = LearnAPI. algorithm (model). names
@@ -98,15 +98,15 @@ function LearnAPI.transform(model::Selector2Fit, X)
98
98
end
99
99
100
100
# fit and transform in one step:
101
- function LearnAPI. transform (algorithm:: Selector2 , X)
101
+ function LearnAPI. transform (algorithm:: FancySelector , X)
102
102
model = fit (algorithm)
103
103
transform (model, X)
104
104
end
105
105
106
106
# note the necessity of overloading `is_static` (`fit` consumes no data):
107
107
@trait (
108
- Selector2 ,
109
- constructor = Selector2 ,
108
+ FancySelector ,
109
+ constructor = FancySelector ,
110
110
is_static = true ,
111
111
tags = (" feature engineering" ,),
112
112
functions = (
120
120
)
121
121
122
122
@testset " test a variation that reports byproducts" begin
123
- algorithm = Selector2 (names= [:x , :w ])
123
+ algorithm = FancySelector (names= [:x , :w ])
124
124
X = DataFrames. DataFrame (rand (3 , 4 ), [:x , :y , :z , :w ])
125
125
model = fit (algorithm) # no data arguments!
126
126
@test ! isdefined (model, :reject )
0 commit comments