添加耗时统计装饰器工具
This commit is contained in:
@@ -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),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user