]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
refactor(weights): align _train with BaseRegressionModel.train
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 24 May 2026 00:40:05 +0000 (02:40 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 24 May 2026 00:40:05 +0000 (02:40 +0200)
Rename _train_default to _train to match the upstream method name (with
underscore prefix to mark it as the internal mirror, since the public
train() method routes between data split paths).

Mirror BaseRegressionModel.train line-for-line with _compose_train_weights
as the single intentional insertion between make_train_test_datasets and
the pipeline application:

- Drop ensure_datetime_series wrapper around unfiltered_df['date']:
  upstream calls .iloc[].strftime() directly.
- Drop **kwargs from self.fit(dd, dk) to match upstream signature.
- Use dk.data_dictionary['train_features'].columns for feature count log,
  matching upstream source of truth.
- Apply the same cosmetic alignment to the timeseries_split path for
  consistency between both train code paths.
- Add docstring documenting the mirror relationship and the single
  functional difference.

quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py

index 97b61b5b4b1e71e8b9c0cd7eb233c76fb6ce980a..92c585c2dae68c93d79b3a92d1afd7cbb462c58d 100644 (file)
@@ -51,7 +51,6 @@ from Utils import (
     REGRESSORS,
     Regressor,
     compose_sample_weights,
-    ensure_datetime_series,
     eval_set_and_weights,
     fit_regressor,
     format_dict,
@@ -1409,7 +1408,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
         logger.info(f"Using data split method: {method}")
 
         if method == QuickAdapterRegressorV3.DATA_SPLIT_METHOD_DEFAULT:
-            return self._train_default(unfiltered_df, pair, dk, **kwargs)
+            return self._train(unfiltered_df, pair, dk, **kwargs)
 
         elif (
             method == QuickAdapterRegressorV3._DATA_SPLIT_METHODS[1]
@@ -1427,9 +1426,8 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
                 training_filter=True,
             )
 
-            dates = ensure_datetime_series(unfiltered_df["date"])
-            start_date = dates.iloc[0].strftime("%Y-%m-%d")
-            end_date = dates.iloc[-1].strftime("%Y-%m-%d")
+            start_date = unfiltered_df["date"].iloc[0].strftime("%Y-%m-%d")
+            end_date = unfiltered_df["date"].iloc[-1].strftime("%Y-%m-%d")
             logger.info(
                 f"-------------------- Training on data from {start_date} to "
                 f"{end_date} --------------------"
@@ -1450,11 +1448,11 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
             dd = self._apply_pipelines(dd, dk, pair)
 
             logger.info(
-                f"Training model on {len(dd['train_features'].columns)} features"
+                f"Training model on {len(dk.data_dictionary['train_features'].columns)} features"
             )
             logger.info(f"Training model on {len(dd['train_features'])} data points")
 
-            model = self.fit(dd, dk, **kwargs)
+            model = self.fit(dd, dk)
 
             end_time = time.time()
 
@@ -1465,14 +1463,21 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
 
             return model
 
-    def _train_default(
+    def _train(
         self,
         unfiltered_df: pd.DataFrame,
         pair: str,
         dk: FreqaiDataKitchen,
         **kwargs,
     ) -> Any:
+        """
+        Mirror of ``BaseRegressionModel.train`` with a single insertion: composition
+        of per-label sample weights via :meth:`_compose_train_weights` between the
+        train/test split and the pipeline application. Routed from :meth:`train`
+        when ``data_split_parameters.method`` is ``train_test_split``.
+        """
         logger.info(f"-------------------- Starting training {pair} --------------------")
+
         start_time = time.time()
 
         features_filtered, labels_filtered = dk.filter_features(
@@ -1482,9 +1487,8 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
             training_filter=True,
         )
 
-        dates = ensure_datetime_series(unfiltered_df["date"])
-        start_date = dates.iloc[0].strftime("%Y-%m-%d")
-        end_date = dates.iloc[-1].strftime("%Y-%m-%d")
+        start_date = unfiltered_df["date"].iloc[0].strftime("%Y-%m-%d")
+        end_date = unfiltered_df["date"].iloc[-1].strftime("%Y-%m-%d")
         logger.info(
             f"-------------------- Training on data from {start_date} to "
             f"{end_date} --------------------"
@@ -1498,12 +1502,15 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
 
         dd = self._apply_pipelines(dd, dk, pair)
 
-        logger.info(f"Training model on {len(dd['train_features'].columns)} features")
+        logger.info(
+            f"Training model on {len(dk.data_dictionary['train_features'].columns)} features"
+        )
         logger.info(f"Training model on {len(dd['train_features'])} data points")
 
-        model = self.fit(dd, dk, **kwargs)
+        model = self.fit(dd, dk)
 
         end_time = time.time()
+
         logger.info(
             f"-------------------- Done training {pair} "
             f"({end_time - start_time:.2f} secs) --------------------"