Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
ebc831bc
Unverified
Commit
ebc831bc
authored
Jul 09, 2019
by
Guolin Ke
Committed by
GitHub
Jul 09, 2019
Browse files
fix bug when using dart with init_model (#2251)
* add test * fix a index bug
parent
291752de
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
4 deletions
+29
-4
src/boosting/dart.hpp
src/boosting/dart.hpp
+4
-4
tests/python_package_test/test_engine.py
tests/python_package_test/test_engine.py
+25
-0
No files found.
src/boosting/dart.hpp
View file @
ebc831bc
...
@@ -171,8 +171,8 @@ class DART: public GBDT {
...
@@ -171,8 +171,8 @@ class DART: public GBDT {
train_score_updater_
->
AddScore
(
models_
[
curr_tree
].
get
(),
cur_tree_id
);
train_score_updater_
->
AddScore
(
models_
[
curr_tree
].
get
(),
cur_tree_id
);
}
}
if
(
!
config_
->
uniform_drop
)
{
if
(
!
config_
->
uniform_drop
)
{
sum_weight_
-=
tree_weight_
[
i
]
*
(
1.0
f
/
(
k
+
1.0
f
));
sum_weight_
-=
tree_weight_
[
i
-
num_init_iteration_
]
*
(
1.0
f
/
(
k
+
1.0
f
));
tree_weight_
[
i
]
*=
(
k
/
(
k
+
1.0
f
));
tree_weight_
[
i
-
num_init_iteration_
]
*=
(
k
/
(
k
+
1.0
f
));
}
}
}
}
}
else
{
}
else
{
...
@@ -189,8 +189,8 @@ class DART: public GBDT {
...
@@ -189,8 +189,8 @@ class DART: public GBDT {
train_score_updater_
->
AddScore
(
models_
[
curr_tree
].
get
(),
cur_tree_id
);
train_score_updater_
->
AddScore
(
models_
[
curr_tree
].
get
(),
cur_tree_id
);
}
}
if
(
!
config_
->
uniform_drop
)
{
if
(
!
config_
->
uniform_drop
)
{
sum_weight_
-=
tree_weight_
[
i
]
*
(
1.0
f
/
(
k
+
config_
->
learning_rate
));;
sum_weight_
-=
tree_weight_
[
i
-
num_init_iteration_
]
*
(
1.0
f
/
(
k
+
config_
->
learning_rate
));;
tree_weight_
[
i
]
*=
(
k
/
(
k
+
config_
->
learning_rate
));
tree_weight_
[
i
-
num_init_iteration_
]
*=
(
k
/
(
k
+
config_
->
learning_rate
));
}
}
}
}
}
}
...
...
tests/python_package_test/test_engine.py
View file @
ebc831bc
...
@@ -480,6 +480,31 @@ class TestEngine(unittest.TestCase):
...
@@ -480,6 +480,31 @@ class TestEngine(unittest.TestCase):
self
.
assertAlmostEqual
(
l1
,
mae
,
places
=
5
)
self
.
assertAlmostEqual
(
l1
,
mae
,
places
=
5
)
os
.
remove
(
model_name
)
os
.
remove
(
model_name
)
def
test_continue_train_dart
(
self
):
X
,
y
=
load_boston
(
True
)
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.1
,
random_state
=
42
)
params
=
{
'boosting_type'
:
'dart'
,
'objective'
:
'regression'
,
'metric'
:
'l1'
,
'verbose'
:
-
1
}
lgb_train
=
lgb
.
Dataset
(
X_train
,
y_train
,
free_raw_data
=
False
)
lgb_eval
=
lgb
.
Dataset
(
X_test
,
y_test
,
reference
=
lgb_train
,
free_raw_data
=
False
)
init_gbm
=
lgb
.
train
(
params
,
lgb_train
,
num_boost_round
=
50
)
evals_result
=
{}
gbm
=
lgb
.
train
(
params
,
lgb_train
,
num_boost_round
=
50
,
valid_sets
=
lgb_eval
,
verbose_eval
=
False
,
evals_result
=
evals_result
,
init_model
=
init_gbm
)
ret
=
mean_absolute_error
(
y_test
,
gbm
.
predict
(
X_test
))
self
.
assertLess
(
ret
,
3.5
)
self
.
assertAlmostEqual
(
evals_result
[
'valid_0'
][
'l1'
][
-
1
],
ret
,
places
=
5
)
for
l1
,
mae
in
zip
(
evals_result
[
'valid_0'
][
'l1'
],
evals_result
[
'valid_0'
][
'mae'
]):
self
.
assertAlmostEqual
(
l1
,
mae
,
places
=
5
)
def
test_continue_train_multiclass
(
self
):
def
test_continue_train_multiclass
(
self
):
X
,
y
=
load_iris
(
True
)
X
,
y
=
load_iris
(
True
)
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.1
,
random_state
=
42
)
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.1
,
random_state
=
42
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment