Skip to content

Commit

Permalink
fix percentile computation for regression objectives (#5848)
Browse files Browse the repository at this point in the history
* Update regression_objective.hpp

* Update regression_objective.hpp

Maybe still need a (1.0 - alpha)

* fix position in percentile calculation

* fix regression metric threshold for l1

---------

Co-authored-by: shiyu1994 <shiyu_k1994@qq.com>
  • Loading branch information
zachary62 and shiyu1994 committed Aug 15, 2023
1 parent 5c9e61d commit 37c3d3f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/objective/regression_objective.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ namespace LightGBM {
for (data_size_t i = 0; i < cnt_data; ++i) { \
ref_data[i] = data_reader(i); \
} \
const double float_pos = static_cast<double>(1.0 - alpha) * cnt_data; \
const data_size_t pos = static_cast<data_size_t>(float_pos); \
const double float_pos = static_cast<double>(cnt_data - 1) * (1.0 - alpha); \
const data_size_t pos = static_cast<data_size_t>(float_pos) + 1; \
if (pos < 1) { \
return ref_data[ArrayArgs<T>::ArgMax(ref_data)]; \
} else if (pos >= cnt_data) { \
return ref_data[ArrayArgs<T>::ArgMin(ref_data)]; \
} else { \
const double bias = float_pos - pos; \
const double bias = float_pos - (pos - 1); \
if (pos > cnt_data / 2) { \
ArrayArgs<T>::ArgMaxAtK(&ref_data, 0, cnt_data, pos - 1); \
T v1 = ref_data[pos - 1]; \
Expand Down
2 changes: 1 addition & 1 deletion tests/python_package_test/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_regression(objective):
elif objective == 'quantile':
assert ret < 1311
else:
assert ret < 338
assert ret < 343
assert evals_result['valid_0']['l2'][-1] == pytest.approx(ret)


Expand Down

0 comments on commit 37c3d3f

Please sign in to comment.