Skip to content

Commit

Permalink
Issue/267 (#268)
Browse files Browse the repository at this point in the history
* fix #267

* fix #267
  • Loading branch information
jeremiedb committed Mar 31, 2024
1 parent b4dfe6f commit 4caa126
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EvoTrees"
uuid = "f6006082-12f8-11e9-0c9c-0d5d367ab1e5"
authors = ["jeremiedb <[email protected]>"]
version = "0.16.6"
version = "0.16.7"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
Expand Down
3 changes: 3 additions & 0 deletions ext/EvoTreesCUDAExt/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function EvoTrees.init_core(params::EvoTrees.EvoTypes{L}, ::Type{<:EvoTrees.GPU}
T = Float32

target_levels = nothing
target_isordered = false
if L == EvoTrees.Logistic
@assert eltype(y_train) <: Real && minimum(y_train) >= 0 && maximum(y_train) <= 1
K = 1
Expand All @@ -22,6 +23,7 @@ function EvoTrees.init_core(params::EvoTrees.EvoTypes{L}, ::Type{<:EvoTrees.GPU}
elseif L == EvoTrees.MLogLoss
if eltype(y_train) <: EvoTrees.CategoricalValue
target_levels = EvoTrees.CategoricalArrays.levels(y_train)
target_isordered = isordered(y_train)
y = UInt32.(EvoTrees.CategoricalArrays.levelcode.(y_train))
elseif eltype(y_train) <: Integer || eltype(y_train) <: Bool || eltype(y_train) <: String || eltype(y_train) <: Char
target_levels = sort(unique(y_train))
Expand Down Expand Up @@ -89,6 +91,7 @@ function EvoTrees.init_core(params::EvoTrees.EvoTypes{L}, ::Type{<:EvoTrees.GPU}
info = Dict(
:fnames => fnames,
:target_levels => target_levels,
:target_isordered => target_isordered,
:edges => edges,
:featbins => featbins,
:feattypes => feattypes,
Expand Down
2 changes: 1 addition & 1 deletion src/MLJ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ end

function predict(::EvoTreeClassifier, fitresult, A)
pred = predict(fitresult, A)
return MMI.UnivariateFinite(fitresult.info[:target_levels], pred, pool=missing)
return MMI.UnivariateFinite(fitresult.info[:target_levels], pred, pool=missing, ordered=fitresult.info[:target_isordered])
end

function predict(::EvoTreeCount, fitresult, A)
Expand Down
3 changes: 3 additions & 0 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function init_core(params::EvoTypes{L}, ::Type{CPU}, data, fnames, y_train, w, o
T = Float32

target_levels = nothing
target_isordered = false
if L == Logistic
@assert eltype(y_train) <: Real && minimum(y_train) >= 0 && maximum(y_train) <= 1
K = 1
Expand All @@ -22,6 +23,7 @@ function init_core(params::EvoTypes{L}, ::Type{CPU}, data, fnames, y_train, w, o
elseif L == MLogLoss
if eltype(y_train) <: CategoricalValue
target_levels = CategoricalArrays.levels(y_train)
target_isordered = isordered(y_train)
y = UInt32.(CategoricalArrays.levelcode.(y_train))
elseif eltype(y_train) <: Integer || eltype(y_train) <: Bool || eltype(y_train) <: String || eltype(y_train) <: Char
target_levels = sort(unique(y_train))
Expand Down Expand Up @@ -87,6 +89,7 @@ function init_core(params::EvoTypes{L}, ::Type{CPU}, data, fnames, y_train, w, o
info = Dict(
:fnames => fnames,
:target_levels => target_levels,
:target_isordered => target_isordered,
:edges => edges,
:featbins => featbins,
:feattypes => feattypes,
Expand Down
12 changes: 12 additions & 0 deletions test/MLJ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,15 @@ end
fit!(mach)
predict(mach, X)
end

##################################################
### issue #267: ordered target
##################################################
@testset "MLJ - supported ordered factor predictions" begin
X = (; x=rand(10))
y = coerce(rand("ab", 10), OrderedFactor)
model = EvoTreeClassifier()
mach = machine(model, X, y) |> fit!
yhat = predict(mach, X)
@assert isordered(yhat)
end

2 comments on commit 4caa126

@jeremiedb
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/103965

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.16.7 -m "<description of version>" 4caa1269e1a663830887e248e980dc63494dfe3e
git push origin v0.16.7

Please sign in to comment.