完成--获取特征工程方法列表
This commit is contained in:
parent
f428efa7db
commit
228581bc68
Binary file not shown.
118
data_process/method_reader_date_feature.py
Normal file
118
data_process/method_reader_date_feature.py
Normal file
@ -0,0 +1,118 @@
|
||||
import yaml
|
||||
from typing import Dict, List
|
||||
import os
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
class MethodReader:
|
||||
"""方法配置读取器"""
|
||||
|
||||
def __init__(self):
|
||||
"""初始化方法读取器"""
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.method_config = self._load_method_config()
|
||||
self.parameter_config = self._load_parameter_config()
|
||||
|
||||
def _load_method_config(self) -> Dict:
|
||||
"""加载方法配置文件"""
|
||||
try:
|
||||
config_path = Path('date_feature/method.yaml')
|
||||
if not config_path.exists():
|
||||
raise FileNotFoundError(f"Method config file not found at {config_path}")
|
||||
|
||||
with open(config_path, 'r', encoding='utf-8') as f:
|
||||
config = yaml.safe_load(f)
|
||||
|
||||
self.logger.info("Successfully loaded method config")
|
||||
return config
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error loading method config: {str(e)}")
|
||||
raise
|
||||
|
||||
def _load_parameter_config(self) -> Dict:
|
||||
"""加载参数配置文件"""
|
||||
try:
|
||||
config_path = Path('date_feature/parameter.yaml')
|
||||
if not config_path.exists():
|
||||
raise FileNotFoundError(f"Parameter config file not found at {config_path}")
|
||||
|
||||
with open(config_path, 'r', encoding='utf-8') as f:
|
||||
config = yaml.safe_load(f)
|
||||
|
||||
self.logger.info("Successfully loaded parameter config")
|
||||
return config
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error loading parameter config: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_preprocessing_methods(self) -> Dict:
|
||||
"""获取预处理方法列表"""
|
||||
try:
|
||||
methods = []
|
||||
|
||||
|
||||
# 获取特征工程方法
|
||||
outlier_methods = list(self.method_config.get('feature_engineering_methods', {}).keys())
|
||||
if outlier_methods:
|
||||
methods.append({
|
||||
"name": "outlier_detector",
|
||||
"description": "异常值检测",
|
||||
"method": outlier_methods
|
||||
})
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"methods": methods
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error getting preprocessing methods: {str(e)}")
|
||||
return {
|
||||
"status": "error",
|
||||
"error": str(e)
|
||||
}
|
||||
|
||||
def get_method_details(self, method_name: str) -> Dict:
|
||||
"""获取指定方法的详细信息"""
|
||||
try:
|
||||
# 在各个方法类别中查找方法原理和优缺点
|
||||
method_info = None
|
||||
for category in ['feature_engineering_methods']:
|
||||
if method_name in self.method_config.get(category, {}):
|
||||
method_info = self.method_config[category][method_name]
|
||||
break
|
||||
|
||||
if method_info is None:
|
||||
raise ValueError(f"Method {method_name} not found in method config")
|
||||
|
||||
# 查找方法参数信息
|
||||
parameter_info = None
|
||||
for category in ['feature_engineering_methods_parameters']:
|
||||
if method_name in self.parameter_config.get(category, {}):
|
||||
parameter_info = self.parameter_config[category][method_name]
|
||||
break
|
||||
|
||||
if parameter_info is None:
|
||||
raise ValueError(f"Method {method_name} not found in parameter config")
|
||||
|
||||
# 组合返回信息
|
||||
return {
|
||||
"status": "success",
|
||||
"method": {
|
||||
"name": method_name,
|
||||
"description": parameter_info.get('description', ''),
|
||||
"principle": method_info.get('principle', ''),
|
||||
"advantages": method_info.get('advantages', []),
|
||||
"disadvantages": method_info.get('disadvantages', []),
|
||||
"applicable_scenarios": method_info.get('applicable_scenarios', []),
|
||||
"parameters": parameter_info.get('parameters', [])
|
||||
}
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error getting method details: {str(e)}")
|
||||
return {
|
||||
"status": "error",
|
||||
"error": str(e)
|
||||
}
|
||||
14
example_method_reader_date_feature.py
Normal file
14
example_method_reader_date_feature.py
Normal file
@ -0,0 +1,14 @@
|
||||
from data_process.method_reader_date_feature import MethodReader
|
||||
|
||||
# 创建方法读取器实例
|
||||
reader = MethodReader()
|
||||
|
||||
# 获取所有预处理方法
|
||||
methods = reader.get_preprocessing_methods()
|
||||
print("预处理方法列表:")
|
||||
print(methods)
|
||||
|
||||
# 获取特定方法的详细信息
|
||||
method_details = reader.get_method_details('KBinsDiscretizer')
|
||||
print("\nKBinsDiscretizer方法详情:")
|
||||
print(method_details)
|
||||
14
example_method_reader_date_process.py
Normal file
14
example_method_reader_date_process.py
Normal file
@ -0,0 +1,14 @@
|
||||
from data_process.method_reader_date_process import MethodReader
|
||||
|
||||
# 创建方法读取器实例
|
||||
reader = MethodReader()
|
||||
|
||||
# 获取所有预处理方法
|
||||
methods = reader.get_preprocessing_methods()
|
||||
print("预处理方法列表:")
|
||||
print(methods)
|
||||
|
||||
# 获取特定方法的详细信息
|
||||
method_details = reader.get_method_details('StandardScaler')
|
||||
print("\nStandardScaler方法详情:")
|
||||
print(method_details)
|
||||
Loading…
Reference in New Issue
Block a user