From 871e7ab7aad692a5e1639655e373c990e6345456 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 20 Feb 2025 06:24:37 +0100 Subject: [PATCH] fix(qav3): handle corner case shape alignement MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../LightGBMRegressorQuickAdapterV35.py | 21 +++++++------------ .../XGBoostRegressorQuickAdapterV35.py | 21 +++++++------------ 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py b/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py index c2889aa..2dfcfb9 100644 --- a/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py +++ b/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py @@ -579,22 +579,15 @@ def period_objective( min_label_period_candles, max_label_period_candles, ) - y_test = [ - y_test.iloc[i : i + label_period_candles] - for i in range(0, len(y_test), label_period_candles) - ] y_pred = pd.Series(y_pred) - y_pred = [ - y_pred.iloc[i : i + label_period_candles] - for i in range(0, len(y_pred), label_period_candles) - ] min_length = min(len(y_test), len(y_pred)) - y_test = y_test[:min_length] - y_pred = y_pred[:min_length] - # trim last chunk if needed - last_chunk_min_length = min(len(y_test[-1]), len(y_pred[-1])) - y_test[-1] = y_test[-1][:last_chunk_min_length] - y_pred[-1] = y_pred[-1][:last_chunk_min_length] + remaining_candles = min_length % label_period_candles + if remaining_candles: + y_test = y_test.iloc[remaining_candles:] + y_pred = y_pred.iloc[remaining_candles:] + indices = range(0, min_length, label_period_candles) + y_test = [y_test.iloc[i : i + label_period_candles] for i in indices] + y_pred = [y_pred.iloc[i : i + label_period_candles] for i in indices] error = sklearn.metrics.root_mean_squared_error(y_test, y_pred) diff --git a/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py b/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py index 86bba78..077c456 100644 --- a/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py +++ b/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py @@ -583,22 +583,15 @@ def period_objective( min_label_period_candles, max_label_period_candles, ) - y_test = [ - y_test.iloc[i : i + label_period_candles] - for i in range(0, len(y_test), label_period_candles) - ] y_pred = pd.Series(y_pred) - y_pred = [ - y_pred.iloc[i : i + label_period_candles] - for i in range(0, len(y_pred), label_period_candles) - ] min_length = min(len(y_test), len(y_pred)) - y_test = y_test[:min_length] - y_pred = y_pred[:min_length] - # trim last chunk if needed - last_chunk_min_length = min(len(y_test[-1]), len(y_pred[-1])) - y_test[-1] = y_test[-1][:last_chunk_min_length] - y_pred[-1] = y_pred[-1][:last_chunk_min_length] + remaining_candles = min_length % label_period_candles + if remaining_candles: + y_test = y_test.iloc[remaining_candles:] + y_pred = y_pred.iloc[remaining_candles:] + indices = range(0, min_length, label_period_candles) + y_test = [y_test.iloc[i : i + label_period_candles] for i in indices] + y_pred = [y_pred.iloc[i : i + label_period_candles] for i in indices] error = sklearn.metrics.root_mean_squared_error(y_test, y_pred) -- 2.43.0