Skip to content

Commit 01f2d7d

Browse files
committed
remove pdf_smoothing option #11
1 parent 4c1f0fc commit 01f2d7d

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

src/MLJDecisionTreeInterface.jl

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ MMI.@mlj_model mutable struct DecisionTreeClassifier <: MMI.Probabilistic
3838
n_subfeatures::Int = 0::(_ ≥ -1)
3939
post_prune::Bool = false
4040
merge_purity_threshold::Float64 = 1.0::(_ ≤ 1)
41-
pdf_smoothing::Float64 = 0.0::(0 ≤ _ ≤ 1)
4241
display_depth::Int = 5::(_ ≥ 1)
4342
rng::Union{AbstractRNG,Integer} = GLOBAL_RNG
4443
end
@@ -103,10 +102,9 @@ function MMI.predict(m::DecisionTreeClassifier, fitresult, Xnew)
103102
tree, classes_seen, integers_seen = fitresult
104103
# retrieve the predicted scores
105104
scores = DT.apply_tree_proba(tree, Xmatrix, integers_seen)
106-
# smooth if required
107-
sm_scores = smooth(scores, m.pdf_smoothing)
105+
108106
# return vector of UF
109-
return MMI.UnivariateFinite(classes_seen, sm_scores)
107+
return MMI.UnivariateFinite(classes_seen, scores)
110108
end
111109

112110

@@ -120,7 +118,6 @@ MMI.@mlj_model mutable struct RandomForestClassifier <: MMI.Probabilistic
120118
n_subfeatures::Int = (-)(1)::(_ ≥ -1)
121119
n_trees::Int = 10::(_ ≥ 2)
122120
sampling_fraction::Float64 = 0.7::(0 < _ ≤ 1)
123-
pdf_smoothing::Float64 = 0.0::(0 ≤ _ ≤ 1)
124121
rng::Union{AbstractRNG,Integer} = GLOBAL_RNG
125122
end
126123

@@ -151,16 +148,14 @@ function MMI.predict(m::RandomForestClassifier, fitresult, Xnew)
151148
Xmatrix = MMI.matrix(Xnew)
152149
forest, classes_seen, integers_seen = fitresult
153150
scores = DT.apply_forest_proba(forest, Xmatrix, integers_seen)
154-
sm_scores = smooth(scores, m.pdf_smoothing)
155-
return MMI.UnivariateFinite(classes_seen, sm_scores)
151+
return MMI.UnivariateFinite(classes_seen, scores)
156152
end
157153

158154

159155
# # ADA BOOST STUMP CLASSIFIER
160156

161157
MMI.@mlj_model mutable struct AdaBoostStumpClassifier <: MMI.Probabilistic
162158
n_iter::Int = 10::(_ ≥ 1)
163-
pdf_smoothing::Float64 = 0.0::(0 ≤ _ ≤ 1)
164159
end
165160

166161
function MMI.fit(m::AdaBoostStumpClassifier, verbosity::Int, X, y)
@@ -185,8 +180,7 @@ function MMI.predict(m::AdaBoostStumpClassifier, fitresult, Xnew)
185180
stumps, coefs, classes_seen, integers_seen = fitresult
186181
scores = DT.apply_adaboost_stumps_proba(stumps, coefs,
187182
Xmatrix, integers_seen)
188-
sm_scores = smooth(scores, m.pdf_smoothing)
189-
return MMI.UnivariateFinite(classes_seen, sm_scores)
183+
return MMI.UnivariateFinite(classes_seen, scores)
190184
end
191185

192186

@@ -239,7 +233,6 @@ MMI.@mlj_model mutable struct RandomForestRegressor <: MMI.Deterministic
239233
n_subfeatures::Int = (-)(1)::(_ ≥ -1)
240234
n_trees::Int = 10::(_ ≥ 2)
241235
sampling_fraction::Float64 = 0.7::(0 < _ ≤ 1)
242-
pdf_smoothing::Float64 = 0.0::(0 ≤ _ ≤ 1)
243236
rng::Union{AbstractRNG,Integer} = GLOBAL_RNG
244237
end
245238

@@ -375,14 +368,6 @@ Train the machine using `fit!(mach, rows=...)`.
375368
376369
- `rng=Random.GLOBAL_RNG`: random number generator or seed
377370
378-
- `pdf_smoothing=0.0`: threshold for smoothing the predicted scores.
379-
Raw leaf-based probabilities are smoothed as follows: If `n` is the
380-
number of observed classes, then each class probability is replaced
381-
by `pdf_smoothing/n`, if it falls below that ratio, and the
382-
resulting vector of probabilities is renormalized. Smoothing is only
383-
applied to classes actually observed in training. Unseen classes
384-
retain zero-probability predictions.
385-
386371
387372
# Operations
388373
@@ -512,9 +497,6 @@ Train the machine with `fit!(mach, rows=...)`.
512497
513498
- `rng=Random.GLOBAL_RNG`: random number generator or seed
514499
515-
- `pdf_smoothing=0.0`: threshold for smoothing the predicted scores of
516-
each tree. See [`DecisionTreeClassifier`](@ref)
517-
518500
519501
# Operations
520502
@@ -586,9 +568,6 @@ Train the machine with `fit!(mach, rows=...)`.
586568
587569
- `n_iter=10`: number of iterations of AdaBoost
588570
589-
- `pdf_smoothing=0.0`: threshold for smoothing the predicted scores.
590-
See [`DecisionTreeClassifier`](@ref)
591-
592571
593572
# Operations
594573

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ rgs = DecisionTreeRegressor()
8383
fitresult, _, _ = MLJBase.fit(rgs, 1, X, ycont)
8484
@test rms(predict(rgs, fitresult, X), ycont) < 1.5
8585

86-
clf = DecisionTreeClassifier(pdf_smoothing=0)
86+
clf = DecisionTreeClassifier()
8787
fitresult, _, _ = MLJBase.fit(clf, 1, X, yfinite)
8888
@test sum(predict(clf, fitresult, X) .== yfinite) == 0 # perfect prediction
8989

0 commit comments

Comments
 (0)