-
Notifications
You must be signed in to change notification settings - Fork 2
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 #12 from Evovest/dev
Dev
- Loading branch information
Showing
28 changed files
with
1,004 additions
and
437 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
authors = ["jeremiedb <[email protected]>"] | ||
name = "NeuroTreeModels" | ||
uuid = "1db4e0a5-a364-4b0c-897c-2bd5a4a3a1f2" | ||
version = "1.2.0" | ||
authors = ["jeremiedb <[email protected]>"] | ||
version = "1.3.0" | ||
|
||
[deps] | ||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" | ||
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" | ||
|
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
|
||
## Installation | ||
|
||
```julia-repl | ||
```julia | ||
] add NeuroTreeModels | ||
``` | ||
|
||
|
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
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,76 @@ | ||
##################################################################### | ||
# WIP: need to adapt the fit! function to support normal DataFrame (not just GroupedOne) | ||
# Have dataloader adapted to DF vs GDF (both at fit init and callback init) | ||
##################################################################### | ||
|
||
using Revise | ||
using Random | ||
using CSV | ||
using DataFrames | ||
using StatsBase | ||
using Statistics: mean, std | ||
using NeuroTreeModels | ||
|
||
using AWS: AWSCredentials, AWSConfig, @service | ||
@service S3 | ||
aws_creds = AWSCredentials(ENV["AWS_ACCESS_KEY_ID_JDB"], ENV["AWS_SECRET_ACCESS_KEY_JDB"]) | ||
aws_config = AWSConfig(; creds=aws_creds, region="ca-central-1") | ||
|
||
path = "share/data/year/year.csv" | ||
raw = S3.get_object("jeremiedb", path, Dict("response-content-type" => "application/octet-stream"); aws_config) | ||
df = DataFrame(CSV.File(raw, header=false)) | ||
df_tot = copy(df) | ||
|
||
path = "share/data/year/year-train-idx.txt" | ||
raw = S3.get_object("jeremiedb", path, Dict("response-content-type" => "application/octet-stream"); aws_config) | ||
train_idx = DataFrame(CSV.File(raw, header=false))[:, 1] .+ 1 | ||
|
||
path = "share/data/year/year-eval-idx.txt" | ||
raw = S3.get_object("jeremiedb", path, Dict("response-content-type" => "application/octet-stream"); aws_config) | ||
eval_idx = DataFrame(CSV.File(raw, header=false))[:, 1] .+ 1 | ||
|
||
transform!(df_tot, "Column1" => identity => "y_raw") | ||
transform!(df_tot, "y_raw" => (x -> (x .- minimum(x)) ./ std(x)) => "y_norm") | ||
select!(df_tot, Not("Column1")) | ||
feature_names = setdiff(names(df_tot), ["y_raw", "y_norm"]) | ||
target_name = "y_norm" | ||
|
||
function percent_rank(x::AbstractVector{T}) where {T} | ||
return tiedrank(x) / (length(x) + 1) | ||
end | ||
|
||
transform!(df_tot, feature_names .=> percent_rank .=> feature_names) | ||
|
||
dtrain = df_tot[train_idx, :]; | ||
deval = df_tot[eval_idx, :]; | ||
dtest = df_tot[(end-51630+1):end, :]; | ||
|
||
config = NeuroTreeRegressor( | ||
loss=:tweedie_deviance, | ||
actA=:identity, | ||
nrounds=200, | ||
depth=4, | ||
ntrees=32, | ||
batchsize=2048, | ||
lr=1e-3, | ||
) | ||
|
||
@time m = NeuroTreeModels.fit( | ||
config, | ||
dtrain; | ||
deval, | ||
target_name, | ||
feature_names, | ||
print_every_n=5, | ||
early_stopping_rounds=2, | ||
metric=:tweedie_deviance, | ||
device=:gpu | ||
); | ||
|
||
p_eval = m(deval); | ||
mse_eval = mean((p_eval .- deval.y_norm) .^ 2) | ||
@info "MSE raw - deval" mse_eval | ||
|
||
p_test = m(dtest); | ||
mse_test = mean((p_test .- dtest.y_norm) .^ 2) * std(df_tot.y_raw)^2 | ||
@info "MSE - dtest" mse_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
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,58 @@ | ||
using NeuroTreeModels | ||
using MLDatasets | ||
using DataFrames | ||
using Statistics: mean | ||
using StatsBase: median | ||
using CategoricalArrays | ||
using Random | ||
using CUDA | ||
using CategoricalArrays | ||
|
||
Random.seed!(123) | ||
|
||
df = MLDatasets.Titanic().dataframe | ||
|
||
# convert string feature to Categorical | ||
transform!(df, :Sex => categorical => :Sex) | ||
transform!(df, :Sex => ByRow(levelcode) => :Sex) | ||
|
||
# treat string feature and missing values | ||
transform!(df, :Age => ByRow(ismissing) => :Age_ismissing) | ||
transform!(df, :Age => (x -> coalesce.(x, median(skipmissing(x)))) => :Age); | ||
|
||
# remove unneeded variables | ||
df = df[:, Not([:PassengerId, :Name, :Embarked, :Cabin, :Ticket])] | ||
|
||
train_ratio = 0.8 | ||
train_indices = randperm(nrow(df))[1:Int(round(train_ratio * nrow(df)))] | ||
|
||
dtrain = df[train_indices, :] | ||
deval = df[setdiff(1:nrow(df), train_indices), :] | ||
|
||
target_name = "Survived" | ||
feature_names = setdiff(names(df), ["Survived"]) | ||
|
||
config = NeuroTreeRegressor( | ||
loss=:logloss, | ||
nrounds=400, | ||
depth=4, | ||
lr=3e-2, | ||
) | ||
|
||
m = NeuroTreeModels.fit( | ||
config, | ||
dtrain; | ||
deval, | ||
target_name, | ||
feature_names, | ||
metric=:logloss, | ||
print_every_n=10, | ||
early_stopping_rounds=3, | ||
device=:cpu | ||
) | ||
|
||
p_train = m(dtrain) | ||
p_eval = m(deval) | ||
|
||
@info mean((p_train .> 0.5) .== (dtrain[!, target_name] .> 0.5)) | ||
@info mean((p_eval .> 0.5) .== (deval[!, target_name] .> 0.5)) |
Oops, something went wrong.
a4f8dc7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
a4f8dc7
There was a problem hiding this comment.
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/105331
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.
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: