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
7076cb8a
Unverified
Commit
7076cb8a
authored
Apr 30, 2020
by
sbruch
Committed by
GitHub
Apr 30, 2020
Browse files
Fix loss computation in rank cross-entropy objective (#3031)
* Fix loss computation * fix test
parent
62a00eb2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
7 deletions
+7
-7
src/objective/rank_objective.hpp
src/objective/rank_objective.hpp
+5
-5
tests/python_package_test/test_sklearn.py
tests/python_package_test/test_sklearn.py
+2
-2
No files found.
src/objective/rank_objective.hpp
View file @
7076cb8a
...
@@ -323,7 +323,7 @@ class RankXENDCG : public RankingObjective {
...
@@ -323,7 +323,7 @@ class RankXENDCG : public RankingObjective {
double
sum_l1
=
0.0
f
;
double
sum_l1
=
0.0
f
;
for
(
data_size_t
i
=
0
;
i
<
cnt
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
cnt
;
++
i
)
{
l1s
[
i
]
=
-
l1s
[
i
]
/
sum_labels
+
rho
[
i
];
l1s
[
i
]
=
-
l1s
[
i
]
/
sum_labels
+
rho
[
i
];
sum_l1
+=
l1s
[
i
];
sum_l1
+=
l1s
[
i
]
/
(
1.
-
rho
[
i
])
;
}
}
if
(
cnt
<=
1
)
{
if
(
cnt
<=
1
)
{
// when cnt <= 1, the l2 and l3 are zeros
// when cnt <= 1, the l2 and l3 are zeros
...
@@ -336,13 +336,13 @@ class RankXENDCG : public RankingObjective {
...
@@ -336,13 +336,13 @@ class RankXENDCG : public RankingObjective {
std
::
vector
<
double
>
l2s
(
cnt
,
0.0
);
std
::
vector
<
double
>
l2s
(
cnt
,
0.0
);
double
sum_l2
=
0.0
;
double
sum_l2
=
0.0
;
for
(
data_size_t
i
=
0
;
i
<
cnt
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
cnt
;
++
i
)
{
l2s
[
i
]
=
(
sum_l1
-
l1s
[
i
]
)
/
(
1
-
rho
[
i
]);
l2s
[
i
]
=
sum_l1
-
(
l1s
[
i
]
/
(
1
.
-
rho
[
i
])
)
;
sum_l2
+=
l2s
[
i
];
sum_l2
+=
l2s
[
i
]
*
rho
[
i
]
/
(
1.
-
rho
[
i
])
;
}
}
for
(
data_size_t
i
=
0
;
i
<
cnt
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
cnt
;
++
i
)
{
auto
l3
=
(
sum_l2
-
l2s
[
i
]
)
/
(
1
-
rho
[
i
]);
auto
l3
=
sum_l2
-
(
l2s
[
i
]
*
rho
[
i
]
/
(
1
.
-
rho
[
i
])
)
;
lambdas
[
i
]
=
static_cast
<
score_t
>
(
l1s
[
i
]
+
rho
[
i
]
*
l2s
[
i
]
+
lambdas
[
i
]
=
static_cast
<
score_t
>
(
l1s
[
i
]
+
rho
[
i
]
*
l2s
[
i
]
+
rho
[
i
]
*
rho
[
i
]
*
l3
);
rho
[
i
]
*
l3
);
hessians
[
i
]
=
static_cast
<
score_t
>
(
rho
[
i
]
*
(
1.0
-
rho
[
i
]));
hessians
[
i
]
=
static_cast
<
score_t
>
(
rho
[
i
]
*
(
1.0
-
rho
[
i
]));
}
}
}
}
...
...
tests/python_package_test/test_sklearn.py
View file @
7076cb8a
...
@@ -130,8 +130,8 @@ class TestSklearn(unittest.TestCase):
...
@@ -130,8 +130,8 @@ class TestSklearn(unittest.TestCase):
eval_metric
=
'ndcg'
,
eval_metric
=
'ndcg'
,
callbacks
=
[
lgb
.
reset_parameter
(
learning_rate
=
lambda
x
:
max
(
0.01
,
0.1
-
0.01
*
x
))])
callbacks
=
[
lgb
.
reset_parameter
(
learning_rate
=
lambda
x
:
max
(
0.01
,
0.1
-
0.01
*
x
))])
self
.
assertLessEqual
(
gbm
.
best_iteration_
,
24
)
self
.
assertLessEqual
(
gbm
.
best_iteration_
,
24
)
self
.
assertGreater
(
gbm
.
best_score_
[
'valid_0'
][
'ndcg@1'
],
0.6
382
)
self
.
assertGreater
(
gbm
.
best_score_
[
'valid_0'
][
'ndcg@1'
],
0.6
211
)
self
.
assertGreater
(
gbm
.
best_score_
[
'valid_0'
][
'ndcg@3'
],
0.6
319
)
self
.
assertGreater
(
gbm
.
best_score_
[
'valid_0'
][
'ndcg@3'
],
0.6
253
)
def
test_regression_with_custom_objective
(
self
):
def
test_regression_with_custom_objective
(
self
):
X
,
y
=
load_boston
(
True
)
X
,
y
=
load_boston
(
True
)
...
...
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