]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(qav3): ensure shape alignement
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 19 Feb 2025 23:12:51 +0000 (00:12 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 19 Feb 2025 23:12:51 +0000 (00:12 +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 6cf2c9605f8cba8628ee36a5d6146c5e9aced194..435658b79dc732b54a57a78c24952435b181cf04 100644 (file)
@@ -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)
 
index 3709690a18d08ea908e846fc370069a2235d0ace..9c6cf1b37c3984bf70d7355d0f4c3ed78dcce28a 100644 (file)
@@ -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)