Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #190

Merged
merged 8 commits into from
Nov 7, 2022
Merged

Dev #190

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,24 @@ config = EvoTreeRegressor(
min_weight=1.0,
rowsample=0.5,
colsample=1.0)
model = fit_evotree(config; x_train = x_train, y_train = y_train)
preds = predict(model, x_eval)
m = fit_evotree(config; x_train, y_train)
preds = m(x_train)
```

## Feature importance

Returns the normalized gain by feature.

```julia
features_gain = importance(model)
features_gain = importance(m)
```

## Plot

Plot a given tree of the model:

```julia
plot(model, 2)
plot(m, 2)
```

![](figures/plot_tree.png)
Expand All @@ -114,6 +114,8 @@ Note that 1st tree is used to set the bias so the first real tree is #2.
## Save/Load

```julia
EvoTrees.save(model, "data/model.bson")
model = EvoTrees.load("data/model.bson");
```
EvoTrees.save(m, "data/model.bson")
m = EvoTrees.load("data/model.bson");
```

A GPU model should be converted into a CPU one before saving: `m_cpu = convert(EvoTree, m_gpu)`.
10 changes: 10 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ From General Registry:
```julia-repl
julia> Pkg.add("EvoTrees")
```


## Save/Load

```julia
EvoTrees.save(m, "data/model.bson")
m = EvoTrees.load("data/model.bson");
```

A GPU model should be converted into a CPU one before saving: `m_cpu = convert(EvoTree, m_gpu)`.
21 changes: 10 additions & 11 deletions experiments/MLJ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using CategoricalArrays
using Distributions
using EvoTrees
using EvoTrees: logit, sigmoid
# import EvoTrees: EvoTreeRegressor, EvoTreeClassifier, EvoTreeCount, EvoTreeGaussian

##################################################
### Regression - small data
Expand Down Expand Up @@ -74,7 +73,7 @@ config = EvoTreeClassifier(
model = fit_evotree(config; x_train, y_train);
model = fit_evotree(config; x_train, y_train, x_eval = x_train, y_eval = y_train, metric=:mlogloss, print_every_n=10, early_stopping_rounds=25);

pred = predict(model, x_train)
pred = model(x_train)
pred_cat = pred .> 0.5
sum((y_train .== "B") .== pred_cat[:, 1]) / length(y_train)

Expand All @@ -90,16 +89,16 @@ fit!(mach, rows = train, verbosity = 1)
rpt = report(mach)
MLJBase.feature_importances(config, mach.fitresult, rpt)

pred_train = predict(tree, selectrows(X, train))
pred_train_mode = predict_mode(tree, selectrows(X, train))
println(cross_entropy(pred_train, selectrows(y, train)) |> mean)
println(sum(pred_train_mode .== y[train]))
pred_train = EvoTrees.predict(mach, selectrows(X, train))
pred_train_mode = predict_mode(mach, selectrows(X, train))
println(cross_entropy(pred_train, selectrows(y_train, train)) |> mean)
println(sum(pred_train_mode .== y_train[train]) / length(train))

pred_test = predict(tree, selectrows(X, test))
pred_test_mode = predict_mode(tree, selectrows(X, test))
println(cross_entropy(pred_test, selectrows(y, test)) |> mean)
println(sum(pred_test_mode .== y[test]))
pred_test_mode = predict_mode(tree, selectrows(X, test))
pred_test = EvoTrees.predict(mach, selectrows(X, test))
pred_test_mode = predict_mode(mach, selectrows(X, test))
println(cross_entropy(pred_test, selectrows(y_train, test)) |> mean)
println(sum(pred_test_mode .== y_train[test]) / length(test))
pred_test_mode = predict_mode(mach, selectrows(X, test))

# using LossFunctions, Plots
# evo_model = EvoTreeClassifier(max_depth=6, η=0.05, λ=1.0, γ=0.0, nrounds=10, nbins=64)
Expand Down
7 changes: 3 additions & 4 deletions experiments/benchmarks-softmax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ params_evo = EvoTreeClassifier(
gamma=0.0,
eta=0.05,
max_depth=6,
min_weight=10.0,
min_weight=1.0,
rowsample=0.5,
colsample=0.5,
nbins=64,
num_class=num_class
nbins=64
)

nobs = Int(1e6)
Expand All @@ -65,7 +64,7 @@ params_evo.device = "cpu"
@time m_evo = fit_evotree(params_evo; x_train, y_train, x_eval=x_train, y_eval=y_train, metric=metric_evo, print_every_n=100);
@time m_evo = fit_evotree(params_evo; x_train, y_train, x_eval=x_train, y_eval=y_train, metric=metric_evo, print_every_n=100);
# @btime fit_evotree($params_evo; x_train=$x_train, y_train=$y_train, x_eval=$x_train, y_eval=$y_train, metric=metric_evo);
# @btime fit_evotree($params_evo; x_train=$x_train, y_train=$y_train);
@time fit_evotree(params_evo; x_train, y_train);
@info "evotrees predict CPU:"
@time pred_evo = EvoTrees.predict(m_evo, x_train);
@btime EvoTrees.predict($m_evo, $x_train);
Expand Down
1 change: 0 additions & 1 deletion experiments/readme_plots_cpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ params1 = EvoTreeRegressor(T=Float32,
@time model = fit_evotree(params1; x_train, y_train, x_eval, y_eval, metric=:mse, print_every_n=25, early_stopping_rounds=20);
# 67.159 ms (77252 allocations: 28.06 MiB)
# @time model = fit_evotree(params1, X_train, Y_train, X_eval = X_eval, Y_eval = Y_eval, print_every_n = 999);
# @btime model = fit_evotree($params1, $X_train, $Y_train, X_eval = $X_eval, Y_eval = $Y_eval);
# Profile.clear() # in case we have any previous profiling data
# @profile fit_evotree(params1, X_train, Y_train, X_eval = X_eval, Y_eval = Y_eval, print_every_n = 25)
# ProfileView.view()
Expand Down
Loading