Unverified Commit 37c3d3fb authored by Zachary Huang's avatar Zachary Huang Committed by GitHub
Browse files

fix percentile computation for regression objectives (#5848)



* 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: default avatarshiyu1994 <shiyu_k1994@qq.com>
parent 5c9e61d1
...@@ -24,14 +24,14 @@ namespace LightGBM { ...@@ -24,14 +24,14 @@ namespace LightGBM {
for (data_size_t i = 0; i < cnt_data; ++i) { \ for (data_size_t i = 0; i < cnt_data; ++i) { \
ref_data[i] = data_reader(i); \ ref_data[i] = data_reader(i); \
} \ } \
const double float_pos = static_cast<double>(1.0 - alpha) * cnt_data; \ 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); \ const data_size_t pos = static_cast<data_size_t>(float_pos) + 1; \
if (pos < 1) { \ if (pos < 1) { \
return ref_data[ArrayArgs<T>::ArgMax(ref_data)]; \ return ref_data[ArrayArgs<T>::ArgMax(ref_data)]; \
} else if (pos >= cnt_data) { \ } else if (pos >= cnt_data) { \
return ref_data[ArrayArgs<T>::ArgMin(ref_data)]; \ return ref_data[ArrayArgs<T>::ArgMin(ref_data)]; \
} else { \ } else { \
const double bias = float_pos - pos; \ const double bias = float_pos - (pos - 1); \
if (pos > cnt_data / 2) { \ if (pos > cnt_data / 2) { \
ArrayArgs<T>::ArgMaxAtK(&ref_data, 0, cnt_data, pos - 1); \ ArrayArgs<T>::ArgMaxAtK(&ref_data, 0, cnt_data, pos - 1); \
T v1 = ref_data[pos - 1]; \ T v1 = ref_data[pos - 1]; \
......
...@@ -142,7 +142,7 @@ def test_regression(objective): ...@@ -142,7 +142,7 @@ def test_regression(objective):
elif objective == 'quantile': elif objective == 'quantile':
assert ret < 1311 assert ret < 1311
else: else:
assert ret < 338 assert ret < 343
assert evals_result['valid_0']['l2'][-1] == pytest.approx(ret) assert evals_result['valid_0']['l2'][-1] == pytest.approx(ret)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment