From: Jérôme Benoit Date: Sun, 24 May 2026 00:40:05 +0000 (+0200) Subject: refactor(weights): align _train with BaseRegressionModel.train X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9953f0c0b2d85282e27fc1244fb437781307cda0;p=freqai-strategies.git refactor(weights): align _train with BaseRegressionModel.train 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. --- diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index 97b61b5..92c585c 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -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) --------------------"