]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(qav3): handle corner case shape alignement
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 20 Feb 2025 05:24:37 +0000 (06:24 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 20 Feb 2025 05:24:37 +0000 (06:24 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py
quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py

index c2889aa4221c62934d0cc9a9b422fb25f8c45945..2dfcfb9e15fd8ec1a9e0717e26b9928bdb23302c 100644 (file)
@@ -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)
 
index 86bba7811193fb0c645402681434beb775861126..077c456b5516f4c93556e6860e802aa19b042774 100644 (file)
@@ -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)