6
6
library(lightgbm )
7
7
8
8
# We will train a model with the following scenarii:
9
- # - Run 1: sum of weights equal to 0.06513 without adjusted regularization (not learning)
10
- # - Run 2: sum of weights equal to 0.06513 with adjusted regularization (learning)
11
- # - Run 3: sum of weights equal to 6513 (x 1e5) with adjusted regularization (learning)
9
+ # - Run 1: sum of weights equal to 6513 (x 1e-5) without adjusted regularization (not learning)
10
+ # - Run 2: sum of weights equal to 6513 (x 1e-5) adjusted regularization (learning)
11
+ # - Run 3: sum of weights equal to 6513 with adjusted regularization (learning)
12
12
13
13
# Setup small weights
14
- weights1 <- rep(1.0 / 100000.0 , 6513L )
15
- weights2 <- rep(1.0 / 100000.0 , 1611L )
14
+ weights1 <- rep(1e-5 , 6513L )
15
+ weights2 <- rep(1e-5 , 1611L )
16
16
17
17
# Load data and create datasets
18
18
data(agaricus.train , package = " lightgbm" )
@@ -23,7 +23,7 @@ test <- agaricus.test
23
23
dtest <- lgb.Dataset.create.valid(dtrain , test $ data , label = test $ label , weight = weights2 )
24
24
valids <- list (test = dtest )
25
25
26
- # Run 1: sum of weights equal to 0.06513 without adjusted regularization (not learning)
26
+ # Run 1: sum of weights equal to 6513 (x 1e-5) without adjusted regularization (not learning)
27
27
# It cannot learn because regularization is too large!
28
28
# min_sum_hessian alone is bigger than the sum of weights, thus you will never learn anything
29
29
params <- list (
@@ -47,7 +47,7 @@ model <- lgb.train(
47
47
weight_loss <- as.numeric(model $ record_evals $ test $ l2 $ eval )
48
48
plot(weight_loss ) # Shows how poor the learning was: a straight line!
49
49
50
- # Run 2: sum of weights equal to 0.06513 with adjusted regularization (learning)
50
+ # Run 2: sum of weights equal to 6513 (x 1e-5) with adjusted regularization (learning)
51
51
# Adjusted regularization just consisting in multiplicating results by 1e4 (x10000)
52
52
# Notice how it learns, there is no issue as we adjusted regularization ourselves
53
53
params <- list (
@@ -71,15 +71,8 @@ model <- lgb.train(
71
71
small_weight_loss <- as.numeric(model $ record_evals $ test $ l2 $ eval )
72
72
plot(small_weight_loss ) # It learns!
73
73
74
- # Run 3: sum of weights equal to 6513 (x 1e5) with adjusted regularization (learning)
75
-
76
- # And now, we are doing as usual
77
- library(lightgbm )
78
- data(agaricus.train , package = " lightgbm" )
79
- train <- agaricus.train
74
+ # Run 3: sum of weights equal to 6513 with adjusted regularization (learning)
80
75
dtrain <- lgb.Dataset(train $ data , label = train $ label )
81
- data(agaricus.test , package = " lightgbm" )
82
- test <- agaricus.test
83
76
dtest <- lgb.Dataset.create.valid(dtrain , test $ data , label = test $ label )
84
77
valids <- list (test = dtest )
85
78
0 commit comments