From 982d0fda1195a4d46e655cec1795a401043449c1 Mon Sep 17 00:00:00 2001 From: aszerW Date: Sun, 26 Oct 2025 00:51:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=80=97=E6=97=B6=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E8=A3=85=E9=A5=B0=E5=99=A8=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/bet_tools.py | 6 +++--- common/utils.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/common/bet_tools.py b/common/bet_tools.py index f46fc2c..427352f 100644 --- a/common/bet_tools.py +++ b/common/bet_tools.py @@ -250,14 +250,14 @@ def compute_metrics( beta = float(clf.coef_[0][0]) return { - "logloss": logloss, + "n_samples": len(df), "brier": brier, - "ece": ece, + "logloss": logloss, "accuracy": acc, "reg_alpha": alpha, "reg_beta": beta, + "ece": ece, # 'ece_bins': bin_stats, - "n_samples": int(total), } diff --git a/common/utils.py b/common/utils.py index 94376fa..51f5c05 100644 --- a/common/utils.py +++ b/common/utils.py @@ -1,4 +1,25 @@ import os +import time +from functools import wraps +from loguru import logger + + +def timeit(func): + """ + 装饰器:计算函数执行时间 + """ + + @wraps(func) + def wrapper(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + logger.info( + f"Function {func.__name__} executed in {end_time - start_time:.4f} seconds" + ) + return result + + return wrapper def ensure_directory_exists(target_path: str, is_file: bool = False):