Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiedb committed Sep 18, 2022
1 parent a616092 commit a83a106
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
11 changes: 0 additions & 11 deletions docs/src/models.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
[EvoTrees.jl](https://github.com/Evovest/EvoTrees.jl) supports four model families:

- EvoTreeRegressor
- Linear (minimize mean-squared error)
- Logistic (minimize cross-entropy)
- L1: minimize mean-absolute error
- Quantile: minimize mean-absolute off the quantile
- EvoTreeClassifier
- EvoTreeCount
- EvoTreeGaussian

## EvoTreeRegressor
```@docs
EvoTreeRegressor
Expand Down
47 changes: 30 additions & 17 deletions experiments/readme_plots_cpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Y_train, Y_eval = Y[𝑖_train], Y[𝑖_eval]
# linear
params1 = EvoTreeRegressor(T=Float64,
loss=:linear, metric=:mse,
nrounds=100, nbins=64,
lambda=0.1, gamma=0.1, eta=0.1,
nrounds=200, nbins=64,
lambda=0.1, gamma=0.1, eta=0.05,
max_depth=6, min_weight=1.0,
rowsample=0.5, colsample=1.0,
rng=123)
Expand All @@ -52,8 +52,8 @@ sqrt(mean((pred_train_linear .- Y_train) .^ 2))
# linear weighted
params1 = EvoTreeRegressor(T=Float64,
loss=:linear, metric=:mse,
nrounds=100, nbins=64,
λ=0.1, γ=0.1, η=1.0,
nrounds=200, nbins=64,
lambda=0.1, gamma=0.1, eta=0.05,
max_depth=6, min_weight=1.0,
rowsample=0.5, colsample=1.0,
rng=123)
Expand Down Expand Up @@ -107,35 +107,48 @@ plot(X_train, Y_train, msize=1, mcolor="gray", mswidth=0, background_color=RGB(1
plot!(X_train[:, 1][x_perm], pred_train_linear[x_perm], color="navy", linewidth=1.5, label="Linear")
plot!(X_train[:, 1][x_perm], pred_train_linear_w[x_perm], color="lightblue", linewidth=1.5, label="LinearW")
plot!(X_train[:, 1][x_perm], pred_train_logistic[x_perm], color="darkred", linewidth=1.5, label="Logistic")
plot!(X_train[:, 1][x_perm], pred_train_poisson[x_perm], color="green", linewidth=1.5, label="Poisson")
plot!(X_train[:, 1][x_perm], pred_train_L1[x_perm], color="pink", linewidth=1.5, label="L1")
savefig("figures/regression_sinus.png")



# Poisson
params1 = EvoTreeCount(
loss=:poisson, metric=:poisson,
nrounds=200, nbins=64,
lambda=0.1, gamma=0.1, eta=0.05,
lambda=0.5, gamma=0.1, eta=0.1,
max_depth=6, min_weight=1.0,
rowsample=0.5, colsample=1.0)
@time model = fit_evotree(params1, X_train, Y_train, X_eval=X_eval, Y_eval=Y_eval, print_every_n=25);
# @btime model = grow_gbtree($X_train, $Y_train, $params1, X_eval = $X_eval, Y_eval = $Y_eval)
@time pred_train_poisson = predict(model, X_train);
@time pred_eval_poisson = predict(model, X_eval)
sqrt(mean((pred_train_poisson .- Y_train) .^ 2))

# Gamma
params1 = EvoTreeRegressor(
loss=:gamma, metric=:gamma,
nrounds=200, nbins=64,
lambda=0.5, gamma=0.1, eta=0.1,
max_depth=6, min_weight=1.0,
rowsample=0.5, colsample=1.0)
@time model = fit_evotree(params1, X_train, Y_train, X_eval=X_eval, Y_eval=Y_eval, print_every_n=25);
@time pred_train_gamma = predict(model, X_train);
sqrt(mean((pred_train_gamma .- Y_train) .^ 2))

# Tweedie
params1 = EvoTreeRegressor(
loss=:tweedie, metric=:tweedie,
nrounds=200, nbins=64,
lambda=0.5, gamma=0.1, eta=0.1,
max_depth=6, min_weight=1.0,
rowsample=0.5, colsample=1.0)
@time model = fit_evotree(params1, X_train, Y_train, X_eval=X_eval, Y_eval=Y_eval, print_every_n=25);
@time pred_train_tweedie = predict(model, X_train);
sqrt(mean((pred_train_tweedie .- Y_train) .^ 2))

x_perm = sortperm(X_train[:, 1])
plot(X_train, Y_train, msize=1, mcolor="gray", mswidth=0, background_color=RGB(1, 1, 1), seriestype=:scatter, xaxis=("feature"), yaxis=("target"), legend=true, label="")
plot!(X_train[:, 1][x_perm], pred_train_linear[x_perm], color="navy", linewidth=1.5, label="Linear")
plot!(X_train[:, 1][x_perm], pred_train_linear_w[x_perm], color="lightblue", linewidth=1.5, label="LinearW")
plot!(X_train[:, 1][x_perm], pred_train_logistic[x_perm], color="darkred", linewidth=1.5, label="Logistic")
plot!(X_train[:, 1][x_perm], pred_train_poisson[x_perm], color="green", linewidth=1.5, label="Poisson")
plot!(X_train[:, 1][x_perm], pred_train_L1[x_perm], color="pink", linewidth=1.5, label="L1")
savefig("figures/regression_sinus.png")

plot!(X_train[:, 1][x_perm], pred_train_poisson[x_perm], color="navy", linewidth=1.5, label="Poisson")
plot!(X_train[:, 1][x_perm], pred_train_gamma[x_perm], color="lightblue", linewidth=1.5, label="Gamma")
plot!(X_train[:, 1][x_perm], pred_train_tweedie[x_perm], color="darkred", linewidth=1.5, label="Tweedie")
savefig("figures/regression_sinus2.png")


###############################
Expand Down
12 changes: 8 additions & 4 deletions src/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function EvoTreeRegressor(; kwargs...)
:nbins => 32,
:alpha => 0.5,
:monotone_constraints => Dict{Int,Int}(),
:metric => :mse,
:metric => :none,
:rng => 123,
:device => "cpu"
)
Expand Down Expand Up @@ -145,7 +145,7 @@ function EvoTreeCount(; kwargs...)
:nbins => 32,
:alpha => 0.5,
:monotone_constraints => Dict{Int,Int}(),
:metric => :mse,
:metric => :none,
:rng => 123,
:device => "cpu"
)
Expand All @@ -169,6 +169,10 @@ function EvoTreeCount(; kwargs...)
args[:loss] = Poisson()
end

if args[:metric] == :poisson
@warn "Poisson metric breaking change.\nStarting with EvoTrees.jl v0.11.0, `:poisson` metric now returns the deviance, while it previously returned the log-likelihood."
end

args[:rng] = mk_rng(args[:rng])::Random.AbstractRNG

model = EvoTreeCount(
Expand Down Expand Up @@ -224,7 +228,7 @@ function EvoTreeClassifier(; kwargs...)
:colsample => 1.0,
:nbins => 32,
:alpha => 0.5,
:metric => :mse,
:metric => :none,
:rng => 123,
:device => "cpu"
)
Expand Down Expand Up @@ -304,7 +308,7 @@ function EvoTreeGaussian(; kwargs...)
:nbins => 32,
:alpha => 0.5,
:monotone_constraints => Dict{Int,Int}(),
:metric => :mse,
:metric => :none,
:rng => 123,
:device => "cpu"
)
Expand Down

0 comments on commit a83a106

Please sign in to comment.