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):