Skip to content
This repository was archived by the owner on Oct 4, 2026. It is now read-only.
Merged
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Unreleased
* Retain nonzero warm-start scores in every boosting round, including row-subsampled training. Predictions remain the learned correction to the external baseline.
* Fix the LossFunctions derivative argument order for regression losses, including `L2DistLoss`, while preserving the built-in logistic derivative API.

# v0.2.0
Expand Down
7 changes: 4 additions & 3 deletions src/jlboost-fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Fit a tree boosting model with a DataFrame, df, and target symbol and allowed fe

* nrounds: Number of trees to fit
* warmstart: A vector of scores from which to start training. Defaults to 0. The warmstart may be
different for every row. This is designed to allow the model to improve upon existing models.
different for every row and is included in every boosting round. Returned predictions contain
only the learned correction; add the baseline scores when predicting with the full model.
* eta: The learning rate. Also known as the weight of each tree in the final summation of trees.
Stored on `WeightedJLBoostTree` so trees can be reweighted after fitting.
* lambda: L2 regularization on leaf scores
Expand Down Expand Up @@ -132,14 +133,14 @@ function jlboost(df, target, features, warm_start::AbstractVector,
idx = row_sampling_strategy(nrow(dfc))
if idx == 1:nrow(dfc)
dfs = dfc
ws = nround == 1 ? warm_start : predict(res_jlt[1:nround-1], dfc)
ws = nround == 1 ? warm_start : warm_start .+ predict(res_jlt[1:nround-1], dfc)
wts = weights
else
dfs = dfc[idx, :]
if nround == 1
ws = warm_start[idx]
else
ws = predict(res_jlt[1:nround-1], dfs)
ws = warm_start[idx] .+ predict(res_jlt[1:nround-1], dfs)
end
wts = weights === nothing ? nothing : weights[idx]
end
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ include("test-weights.jl")
include("test-xgboost-accuracy.jl")

include("test-loss-derivatives.jl")

include("test-warm-start.jl")
49 changes: 49 additions & 0 deletions test/test-warm-start.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using JLBoost
using Test
using DataFrames
using LossFunctions: L2DistLoss
using Random

@testset "Warm starts persist across logistic rounds" begin
df = DataFrame(x = zeros(8), y = Float64[0, 0, 0, 1, 0, 1, 1, 1])
baseline = collect(range(-0.4, 1.0; length = 8))
original = copy(baseline)
weights = Float64[1, 2, 3, 4, 4, 3, 2, 1]
eta, lambda = 0.3, 0.7
for rounds in [1, 2, 4]
# Independent Newton updates for a constant leaf, on the full score.
correction = 0.0
for _ in 1:rounds
p = 1 ./ (1 .+ exp.(-(baseline .+ correction)))
G = sum(weights .* (p .- df.y))
H = sum(weights .* p .* (1 .- p))
correction -= eta * G / (H + lambda)
end
model = jlboost(df, :y, [:x], baseline, LogitLogLoss();
nrounds = rounds, max_depth = 1, min_child_weight = 0,
weights, eta, lambda)
# Predictions remain the correction; callers add the external baseline.
@test predict(model, df) ≈ fill(correction, 8)
@test baseline == original
end
end

@testset "Warm-start regression equals residual-target regression" begin
x = collect(range(-2.0, 2.0; length = 40))
baseline = 0.7 .+ 0.2 .* x
df = DataFrame(x = x, y = baseline .+ ifelse.(x .< 0, -1.0, 2.0))
residual = DataFrame(x = x, y = df.y .- baseline)
original = copy(baseline)
for subsample in [1.0, 0.5], weighted in [false, true], rounds in [1, 2, 4]
weights = weighted ? Float64.(1 .+ mod.(1:40, 3)) : nothing
settings = (; nrounds = rounds, max_depth = 2, eta = 0.3,
lambda = 0.5, min_child_weight = 0, subsample, weights)
# Same random rows in each pair, testing baseline/weight row alignment.
Random.seed!(821)
warm = jlboost(df, :y, [:x], baseline, L2DistLoss(); settings...)
Random.seed!(821)
cold = jlboost(residual, :y, [:x], zeros(40), L2DistLoss(); settings...)
@test predict(warm, df) ≈ predict(cold, residual)
@test baseline == original
end
end
Loading