1
1
# # OVERLOADING TRAIT DEFAULTS RELEVANT TO MODELS
2
2
3
- StatisticalTraits. docstring (M:: Type{<:MLJType} ) = name (M)
4
- StatisticalTraits. docstring (M:: Type{<:Model} ) =
3
+ # unexported aliases:
4
+ const Detector = Union{SupervisedDetector,UnsupervisedDetector}
5
+ const ProbabilisticDetector = Union{ProbabilisticSupervisedDetector,
6
+ ProbabilisticUnsupervisedDetector}
7
+ const DeterministicDetector = Union{DeterministicSupervisedDetector,
8
+ DeterministicUnsupervisedDetector}
9
+
10
+ const StatTraits = StatisticalTraits
11
+
12
+ StatTraits. docstring (M:: Type{<:MLJType} ) = name (M)
13
+ StatTraits. docstring (M:: Type{<:Model} ) =
5
14
" $(name (M)) from $(package_name (M)) .jl.\n " *
6
15
" [Documentation]($(package_url (M)) )."
7
16
8
- StatisticalTraits. is_supervised (:: Type{<:Supervised} ) = true
9
- StatisticalTraits. prediction_type (:: Type{<:Deterministic} ) = :deterministic
10
- StatisticalTraits. prediction_type (:: Type{<:Probabilistic} ) = :probabilistic
11
- StatisticalTraits. prediction_type (:: Type{<:Interval} ) = :interval
17
+ StatTraits. is_supervised (:: Type{<:Supervised} ) = true
18
+
19
+ StatTraits. prediction_type (:: Type{<:Deterministic} ) = :deterministic
20
+ StatTraits. prediction_type (:: Type{<:Probabilistic} ) = :probabilistic
21
+ StatTraits. prediction_type (:: Type{<:Interval} ) = :interval
22
+ StatTraits. prediction_type (:: Type{<:ProbabilisticDetector} ) =
23
+ :probabilistic
24
+ StatTraits. prediction_type (:: Type{<:DeterministicDetector} ) =
25
+ :deterministic
26
+
27
+ StatTraits. target_scitype (:: Type{<:ProbabilisticDetector} ) =
28
+ AbstractVector{<: Union{Missing,OrderedFactor{2}} }
29
+ StatTraits. target_scitype (:: Type{<:DeterministicDetector} ) =
30
+ AbstractVector{<: Union{Missing,OrderedFactor{2}} }
12
31
13
32
# implementation is deferred as it requires methodswith which depends upon
14
33
# InteractiveUtils which we don't want to bring here as a dependency
@@ -18,13 +37,13 @@ implemented_methods(model) = implemented_methods(typeof(model))
18
37
implemented_methods (:: LightInterface , M) = errlight (" implemented_methods" )
19
38
20
39
for M in ABSTRACT_MODEL_SUBTYPES
21
- @eval (StatisticalTraits . abstract_type (:: Type{<:$M} ) = $ M)
40
+ @eval (StatTraits . abstract_type (:: Type{<:$M} ) = $ M)
22
41
end
23
42
24
- StatisticalTraits . fit_data_scitype (M:: Type{<:Unsupervised} ) =
43
+ StatTraits . fit_data_scitype (M:: Type{<:Unsupervised} ) =
25
44
Tuple{input_scitype (M)}
26
- StatisticalTraits . fit_data_scitype (:: Type{<:Static} ) = Tuple{}
27
- function StatisticalTraits . fit_data_scitype (M:: Type{<:Supervised} )
45
+ StatTraits . fit_data_scitype (:: Type{<:Static} ) = Tuple{}
46
+ function StatTraits . fit_data_scitype (M:: Type{<:Supervised} )
28
47
I = input_scitype (M)
29
48
T = target_scitype (M)
30
49
ret = Tuple{I,T}
@@ -37,24 +56,42 @@ function StatisticalTraits.fit_data_scitype(M::Type{<:Supervised})
37
56
end
38
57
return ret
39
58
end
59
+ StatTraits. fit_data_scitype (M:: Type{<:UnsupervisedAnnotator} ) =
60
+ Tuple{input_scitype (M)}
61
+ StatTraits. fit_data_scitype (M:: Type{<:SupervisedAnnotator} ) =
62
+ Tuple{input_scitype (M),target_scitype (M)}
63
+
64
+ # In special case of `UnsupervisedProbabilisticDetector`, and
65
+ # `UnsupervsedDeterministicDetector` we allow the target as an
66
+ # optional argument to `fit` (that is ignored) so that the `machine`
67
+ # constructor will accept it as a valid argument, which then enables
68
+ # *evaluation* of the detector with labeled data:
69
+ StatTraits. fit_data_scitype (M:: Type {<: Union {
70
+ ProbabilisticUnsupervisedDetector,
71
+ DeterministicUnsupervisedDetector}}) =
72
+ Union{Tuple{input_scitype (M)},
73
+ Tuple{input_scitype (M),target_scitype (M)}}
40
74
41
- StatisticalTraits . transform_scitype (M:: Type{<:Unsupervised} ) =
75
+ StatTraits . transform_scitype (M:: Type{<:Unsupervised} ) =
42
76
output_scitype (M)
43
77
44
- StatisticalTraits . inverse_transform_scitype (M:: Type{<:Unsupervised} ) =
78
+ StatTraits . inverse_transform_scitype (M:: Type{<:Unsupervised} ) =
45
79
input_scitype (M)
46
80
47
- StatisticalTraits. predict_scitype (M:: Type{<:Deterministic} ) = target_scitype (M)
81
+ StatTraits. predict_scitype (M:: Type {<: Union {
82
+ Deterministic,DeterministicDetector}}) = target_scitype (M)
48
83
49
84
50
- # # FALLBACKS FOR `predict_scitype` FOR `Probabilistic` MODELS
85
+ # # FALLBACKS FOR `predict_scitype` FOR `Probabilistic` and
86
+ # # `ProbabilisticDetector` MODELS
51
87
52
88
# This seems less than ideal but should reduce the number of `Unknown`
53
89
# in `prediction_type` for models which, historically, have not
54
90
# implemented the trait.
55
91
56
- StatisticalTraits. predict_scitype (M:: Type{<:Probabilistic} ) =
57
- _density (target_scitype (M))
92
+ StatTraits. predict_scitype (
93
+ M:: Type{<:Union{Probabilistic,ProbabilisticDetector}}
94
+ ) = _density (target_scitype (M))
58
95
59
96
_density (:: Any ) = Unknown
60
97
for T in [:Continuous , :Count , :Textual ]
@@ -78,6 +115,7 @@ for T in [:Finite,
78
115
end )
79
116
end
80
117
118
+
81
119
for T in [:Finite , :Multiclass , :OrderedFactor ]
82
120
eval (quote
83
121
_density (:: Type{AbstractArray{<:$T{N},D}} ) where {N,D} =
0 commit comments