From: Jérôme Benoit Date: Sun, 24 May 2026 00:06:18 +0000 (+0200) Subject: feat(weights): compose per-label weights with temporal decay before model.fit X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=635a3b9e06d1e69ceea80cd4199b6b6453c0ffa1;p=freqai-strategies.git feat(weights): compose per-label weights with temporal decay before model.fit --- diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index 661bce1..99c3b06 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -50,6 +50,7 @@ from Utils import ( LABEL_COLUMNS, REGRESSORS, Regressor, + compose_sample_weights, ensure_datetime_series, eval_set_and_weights, fit_regressor, @@ -114,6 +115,40 @@ class QuickAdapterRegressorV3(BaseRegressionModel): if not c.endswith(self._LABEL_WEIGHT_SUFFIX) ] + def _compose_train_weights( + self, + dd: dict[str, Any], + unfiltered_df: pd.DataFrame, + dk: FreqaiDataKitchen, + ) -> dict[str, Any]: + weight_cols = { + label: f"{label}{self._LABEL_WEIGHT_SUFFIX}" + for label in dk.label_list + if f"{label}{self._LABEL_WEIGHT_SUFFIX}" in unfiltered_df.columns + } + if not weight_cols: + return dd + label_weights_map: dict[str, NDArray] = {} + for label, weight_col in weight_cols.items(): + series = unfiltered_df[weight_col] + train_w = series.reindex(dd["train_features"].index, fill_value=1.0).to_numpy(dtype=float) + label_weights_map[label] = train_w + dd["train_weights"] = compose_sample_weights( + np.asarray(dd["train_weights"], dtype=float), + label_weights_map, + ) + if dd.get("test_features") is not None and len(dd["test_features"]) > 0: + test_map: dict[str, NDArray] = {} + for label, weight_col in weight_cols.items(): + series = unfiltered_df[weight_col] + test_w = series.reindex(dd["test_features"].index, fill_value=1.0).to_numpy(dtype=float) + test_map[label] = test_w + dd["test_weights"] = compose_sample_weights( + np.asarray(dd["test_weights"], dtype=float), + test_map, + ) + return dd + _SQRT_2: Final[float] = np.sqrt(2.0) _OPTUNA_LABEL_N_OBJECTIVES: Final[int] = 7