-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Evovest/MLJ
Mlj
- Loading branch information
Showing
10 changed files
with
138 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
name = "EvoTrees" | ||
uuid = "f6006082-12f8-11e9-0c9c-0d5d367ab1e5" | ||
authors = ["jeremiedb <[email protected]>"] | ||
version = "0.2.0" | ||
authors = ["jeremiedb <[email protected]>"] | ||
version = "0.2.1" | ||
|
||
[compat] | ||
julia = "1" | ||
|
||
[deps] | ||
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" | ||
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
MLJ = "add582a8-e3ab-11e8-2d5e-e98b27df1bc7" | ||
MLJBase = "a7f614a8-145f-11e9-1d2a-a57a1082229d" | ||
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" | ||
SortingAlgorithms = "a2af1166-a08f-5f64-846c-94a0d3cef48c" | ||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | ||
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" | ||
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
Traceur = "37b6cedf-1f77-55f8-9503-c64b63398394" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
module EvoTrees | ||
|
||
export grow_tree!, grow_gbtree, Tree, Node, Params, predict, EvoTreeRegressor, EvoTreeRegressorR | ||
|
||
using DataFrames | ||
using Statistics | ||
using CSV | ||
using Base.Threads: @threads | ||
using StatsBase: sample | ||
|
||
export grow_tree!, grow_gbtree, Tree, Node, Params, predict, EvoTreeRegressor, EvoTreeRegressorR | ||
import MLJ | ||
import MLJBase | ||
|
||
include("struct.jl") | ||
include("loss.jl") | ||
include("eval.jl") | ||
include("predict.jl") | ||
include("tree_vector.jl") | ||
include("histogram.jl") | ||
include("MLJ.jl") | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
function MLJ.clean!(model::EvoTreeRegressor) | ||
warning = "All Good!" | ||
if model.nrounds < 1 | ||
warning *= "Need nrounds ≥ 1. Resetting nrounds=1. " | ||
model.nrounds = 1 | ||
end | ||
if model.λ < 0 | ||
warning *= "Need λ ≥ 0. Resetting λ=0. " | ||
model.λ = 0.0 | ||
end | ||
if model.γ < 0 | ||
warning *= "Need γ ≥ 0. Resetting γ=0. " | ||
model.γ = 0.0 | ||
end | ||
if model.η <= 0 | ||
warning *= "Need η > 0. Resetting η=0.001. " | ||
model.η = 0.001 | ||
end | ||
if model.max_depth < 1 | ||
warning *= "Need max_depth ≥ 0. Resetting max_depth=0. " | ||
model.max_depth = 1 | ||
end | ||
if model.min_weight < 0 | ||
warning *= "Need min_weight ≥ 0. Resetting min_weight=0. " | ||
model.min_weight = 0.0 | ||
end | ||
if model.rowsample < 0 | ||
warning *= "Need rowsample ≥ 0. Resetting rowsample=0. " | ||
model.rowsample = 0.0 | ||
end | ||
if model.rowsample > 1 | ||
warning *= "Need rowsample <= 1. Resetting rowsample=1. " | ||
model.rowsample = 1.0 | ||
end | ||
if model.colsample < 0 | ||
warning *= "Need colsample ≥ 0. Resetting colsample=0. " | ||
model.colsample = 0.0 | ||
end | ||
if model.colsample > 1 | ||
warning *= "Need colsample <= 1. Resetting colsample=1. " | ||
model.colsample = 1.0 | ||
end | ||
if model.nbins > 250 | ||
warning *= "Need nbins <= 250. Resetting nbins=250. " | ||
model.nbins = 250 | ||
end | ||
return warning | ||
end | ||
|
||
function MLJBase.fit(model::EvoTreeRegressor, verbosity::Integer, X, y) | ||
Xmatrix = MLJBase.matrix(X) | ||
fitresult = grow_gbtree(Xmatrix, y, model, verbosity = verbosity) | ||
cache = nothing | ||
report = nothing | ||
return fitresult, cache, report | ||
end | ||
|
||
function MLJBase.predict(model::EvoTreeRegressor, fitresult, Xnew) | ||
Xmatrix = MLJBase.matrix(Xnew) | ||
pred = pred(fitresult, Xmatrix) | ||
return pred | ||
end | ||
|
||
# shared metadata | ||
const EvoTypes = Union{EvoTreeRegressor} | ||
MLJBase.input_is_multivariate(::Type{<:EvoTreeRegressor}) = true | ||
MLJBase.input_scitype_union(::Type{<:EvoTreeRegressor}) = MLJBase.Continuous | ||
MLJBase.target_scitype_union(::Type{<:EvoTreeRegressor}) = MLJBase.Continuous | ||
|
||
MLJBase.package_name(::Type{<:EvoTypes}) = "EvoTrees" | ||
MLJBase.package_url(::Type{<:EvoTypes}) = "https://github.com/Evovest/EvoTrees.jl" | ||
MLJBase.is_pure_julia(::Type{<:EvoTypes}) = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Tables | ||
using MLJ | ||
import EvoTrees: EvoTreeRegressor | ||
using EvoTrees: logit, sigmoid | ||
|
||
features = rand(10_000) .* 5 .- 2 | ||
X = reshape(features, (size(features)[1], 1)) | ||
Y = sin.(features) .* 0.5 .+ 0.5 | ||
Y = logit(Y) + randn(size(Y)) | ||
Y = sigmoid(Y) | ||
y=Y | ||
X = Tables.table(X) | ||
|
||
@load EvoTreeRegressor | ||
tree_model = EvoTreeRegressor(max_depth=5) | ||
tree = machine(tree_model, X, y) | ||
train, test = partition(eachindex(y), 0.7, shuffle=true); # 70:30 split | ||
fit!(tree, rows=train) | ||
yhat = predict(tree, X[test,:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters