From: Jérôme Benoit Date: Fri, 14 Mar 2025 18:21:20 +0000 (+0100) Subject: perf(qav3): use optimized mean computation X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0b675b4e894ee244b0ccc61ce6cd5cf1463dcc79;p=freqai-strategies.git perf(qav3): use optimized mean computation Signed-off-by: Jérôme Benoit --- diff --git a/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py b/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py index ee1fcf4..f5017a1 100644 --- a/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py +++ b/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py @@ -1,5 +1,6 @@ import logging import json +from statistics import fmean from typing import Any from pathlib import Path @@ -606,12 +607,12 @@ def period_objective( ] y_pred = [y_pred[i : i + label_window] for i in range(0, len(y_pred), label_window)] - error = 0.0 - for y_t, y_p, t_w in zip(y_test, y_pred, test_weights): - error += sklearn.metrics.root_mean_squared_error(y_t, y_p, sample_weight=t_w) - error /= len(y_test) + errors = [ + sklearn.metrics.root_mean_squared_error(y_t, y_p, sample_weight=t_w) + for y_t, y_p, t_w in zip(y_test, y_pred, test_weights) + ] - return error + return fmean(errors) def hp_objective( diff --git a/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py b/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py index 4a3f622..9f54617 100644 --- a/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py +++ b/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py @@ -1,5 +1,6 @@ import logging import json +from statistics import fmean from typing import Any from pathlib import Path @@ -614,12 +615,12 @@ def period_objective( ] y_pred = [y_pred[i : i + label_window] for i in range(0, len(y_pred), label_window)] - error = 0.0 - for y_t, y_p, t_w in zip(y_test, y_pred, test_weights): - error += sklearn.metrics.root_mean_squared_error(y_t, y_p, sample_weight=t_w) - error /= len(y_test) + errors = [ + sklearn.metrics.root_mean_squared_error(y_t, y_p, sample_weight=t_w) + for y_t, y_p, t_w in zip(y_test, y_pred, test_weights) + ] - return error + return fmean(errors) def hp_objective(