From a7bf6dbe0f223b3511afa6c4b4cd242c3523f234 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 20 Feb 2025 00:12:51 +0100 Subject: [PATCH] fix(qav3): ensure 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 | 26 +++++-------------- .../XGBoostRegressorQuickAdapterV35.py | 26 +++++-------------- 2 files changed, 14 insertions(+), 38 deletions(-) diff --git a/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py b/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py index 6cf2c96..435658b 100644 --- a/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py +++ b/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py @@ -588,25 +588,13 @@ def period_objective( y_pred.iloc[i : i + label_period_candles] for i in range(0, len(y_pred), label_period_candles) ] - max_chunk_length = max(len(chunk) for chunk in y_test + y_pred) - y_test = [ - np.pad( - chunk, - (0, max_chunk_length - len(chunk)), - mode="constant", - constant_values=np.nan, - ) - for chunk in y_test - ] - y_pred = [ - np.pad( - chunk, - (0, max_chunk_length - len(chunk)), - mode="constant", - constant_values=np.nan, - ) - for chunk in y_pred - ] + 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 + min_last_chunk_length = min(len(y_test[-1]), len(y_pred[-1])) + y_test[-1] = y_test[-1][:min_last_chunk_length] + y_pred[-1] = y_pred[-1][:min_last_chunk_length] 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 3709690..9c6cf1b 100644 --- a/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py +++ b/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py @@ -592,25 +592,13 @@ def period_objective( y_pred.iloc[i : i + label_period_candles] for i in range(0, len(y_pred), label_period_candles) ] - max_chunk_length = max(len(chunk) for chunk in y_test + y_pred) - y_test = [ - np.pad( - chunk, - (0, max_chunk_length - len(chunk)), - mode="constant", - constant_values=np.nan, - ) - for chunk in y_test - ] - y_pred = [ - np.pad( - chunk, - (0, max_chunk_length - len(chunk)), - mode="constant", - constant_values=np.nan, - ) - for chunk in y_pred - ] + 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 + min_last_chunk_length = min(len(y_test[-1]), len(y_pred[-1])) + y_test[-1] = y_test[-1][:min_last_chunk_length] + y_pred[-1] = y_pred[-1][:min_last_chunk_length] error = sklearn.metrics.root_mean_squared_error(y_test, y_pred) -- 2.43.0