|
|
|
|
@ -10,6 +10,7 @@ from sklearn.preprocessing import StandardScaler
|
|
|
|
|
import pickle
|
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
import logging
|
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
|
|
class Features(BaseModel):
|
|
|
|
|
"""
|
|
|
|
|
@ -189,6 +190,7 @@ class FeatureWeightApplier:
|
|
|
|
|
class FeatureNormalizer:
|
|
|
|
|
"""特征归一化处理类"""
|
|
|
|
|
def __init__(self, config: Dict[str, Any]):
|
|
|
|
|
self.config = config
|
|
|
|
|
self.feature_groups = {}
|
|
|
|
|
self.scalers = {}
|
|
|
|
|
|
|
|
|
|
@ -232,6 +234,21 @@ class FeatureNormalizer:
|
|
|
|
|
Args:
|
|
|
|
|
path: 加载路径
|
|
|
|
|
"""
|
|
|
|
|
# 如果主路径不存在,尝试从默认路径复制
|
|
|
|
|
if not os.path.exists(path):
|
|
|
|
|
default_path = os.path.join(
|
|
|
|
|
os.path.dirname(__file__),
|
|
|
|
|
'..',
|
|
|
|
|
self.config['paths']['normalizer']['default']
|
|
|
|
|
)
|
|
|
|
|
if os.path.exists(default_path):
|
|
|
|
|
# 确保目标目录存在
|
|
|
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
|
|
shutil.copyfile(default_path, path)
|
|
|
|
|
logging.info(f"Copied normalizer from default path: {default_path} to {path}")
|
|
|
|
|
else:
|
|
|
|
|
raise FileNotFoundError(f"No normalizer found in either path: {path} or {default_path}")
|
|
|
|
|
|
|
|
|
|
with open(path, 'rb') as f:
|
|
|
|
|
self.scalers = pickle.load(f)
|
|
|
|
|
|
|
|
|
|
|