-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
172 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
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,152 @@ | ||
using Statistics | ||
using StatsBase: sample | ||
using EvoTrees: sigmoid, logit | ||
using EvoTrees: check_args, check_parameter | ||
using Random: seed! | ||
|
||
# prepare a dataset | ||
seed!(123) | ||
nobs = 2_000 | ||
features = rand(nobs) .* 5 | ||
X = reshape(features, (size(features)[1], 1)) | ||
Y = sin.(features) .* 0.5 .+ 0.5 | ||
Y = logit(Y) + randn(size(Y)) .* 0.1 | ||
Y = sigmoid(Y) | ||
is = collect(1:size(X, 1)) | ||
|
||
# train-eval split | ||
i_sample = sample(is, size(is, 1), replace=false) | ||
train_size = 0.8 | ||
i_train = i_sample[1:floor(Int, train_size * size(is, 1))] | ||
i_eval = i_sample[floor(Int, train_size * size(is, 1))+1:end] | ||
|
||
x_train, x_eval = X[i_train, :], X[i_eval, :] | ||
y_train, y_eval = Y[i_train], Y[i_eval] | ||
|
||
Yc = (Y .> 0.8) .+ 1 | ||
y_train_c, y_eval_c = Yc[i_train], Yc[i_eval] | ||
|
||
@testset "oblivious regressor" begin | ||
@testset for loss in [:mse, :logloss, :quantile, :l1, :gamma, :tweedie] | ||
|
||
metric = loss == :l1 ? :mae : loss | ||
|
||
config = EvoTreeRegressor( | ||
loss=loss, | ||
tree_type="oblivious", | ||
nrounds=200, | ||
nbins=32, | ||
rng=123, | ||
) | ||
|
||
model, cache = EvoTrees.init(config, x_train, y_train) | ||
preds_ini = model(x_eval) | ||
mse_error_ini = mean(abs.(preds_ini .- y_eval) .^ 2) | ||
model = fit_evotree( | ||
config; | ||
x_train, | ||
y_train, | ||
x_eval, | ||
y_eval, | ||
metric=metric, | ||
print_every_n=25 | ||
) | ||
|
||
preds = model(x_eval) | ||
mse_error = mean(abs.(preds .- y_eval) .^ 2) | ||
mse_gain_pct = mse_error / mse_error_ini - 1 | ||
@test mse_gain_pct < -0.75 | ||
|
||
end | ||
end | ||
|
||
@testset "oblivious count" begin | ||
|
||
config = EvoTreeCount( | ||
tree_type="oblivious", | ||
nrounds=200, | ||
nbins=32, | ||
rng=123, | ||
) | ||
|
||
model, cache = EvoTrees.init(config, x_train, y_train) | ||
preds_ini = model(x_eval) | ||
mse_error_ini = mean(abs.(preds_ini .- y_eval) .^ 2) | ||
model = fit_evotree( | ||
config; | ||
x_train, | ||
y_train, | ||
x_eval, | ||
y_eval, | ||
metric=:poisson, | ||
print_every_n=25 | ||
) | ||
|
||
preds = model(x_eval) | ||
mse_error = mean(abs.(preds .- y_eval) .^ 2) | ||
mse_gain_pct = mse_error / mse_error_ini - 1 | ||
@test mse_gain_pct < -0.75 | ||
|
||
end | ||
|
||
@testset "oblivious MLE" begin | ||
@testset for loss in [:gaussian_mle, :logistic_mle] | ||
|
||
config = EvoTreeMLE( | ||
loss=loss, | ||
tree_type="oblivious", | ||
nrounds=200, | ||
nbins=32, | ||
rng=123, | ||
) | ||
|
||
model, cache = EvoTrees.init(config, x_train, y_train) | ||
preds_ini = model(x_eval)[:, 1] | ||
mse_error_ini = mean(abs.(preds_ini .- y_eval) .^ 2) | ||
model = fit_evotree( | ||
config; | ||
x_train, | ||
y_train, | ||
x_eval, | ||
y_eval, | ||
metric=loss, | ||
print_every_n=25 | ||
) | ||
|
||
preds = model(x_eval)[:, 1] | ||
mse_error = mean(abs.(preds .- y_eval) .^ 2) | ||
mse_gain_pct = mse_error / mse_error_ini - 1 | ||
@test mse_gain_pct .< 0.75 | ||
|
||
end | ||
end | ||
|
||
@testset "oblivious classifier" begin | ||
|
||
config = EvoTreeClassifier( | ||
tree_type="oblivious", | ||
nrounds=200, | ||
nbins=32, | ||
rng=123, | ||
) | ||
|
||
model, cache = EvoTrees.init(config, x_train, y_train_c) | ||
preds_ini = model(x_eval) | ||
acc_ini = mean(map(argmax, eachrow(preds_ini)) .== y_eval_c) | ||
|
||
model = fit_evotree( | ||
config; | ||
x_train, | ||
y_train=y_train_c, | ||
x_eval, | ||
y_eval=y_eval_c, | ||
metric=:mlogloss, | ||
print_every_n=25 | ||
) | ||
|
||
preds = model(x_eval) | ||
acc = mean(map(argmax, eachrow(preds)) .== y_eval_c) | ||
|
||
@test acc > 0.9 | ||
|
||
end |
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