From 228581bc687bda423ea1b197ce57c067daa230a9 Mon Sep 17 00:00:00 2001 From: haotian <2421912570@qq.com> Date: Mon, 17 Feb 2025 15:27:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90--=E8=8E=B7=E5=8F=96=E7=89=B9?= =?UTF-8?q?=E5=BE=81=E5=B7=A5=E7=A8=8B=E6=96=B9=E6=B3=95=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../method_reader_date_feature.cpython-39.pyc | Bin 0 -> 3498 bytes data_process/method_reader_date_feature.py | 118 ++++++++++++++++++ example_method_reader_date_feature.py | 14 +++ example_method_reader_date_process.py | 14 +++ 4 files changed, 146 insertions(+) create mode 100644 data_process/__pycache__/method_reader_date_feature.cpython-39.pyc create mode 100644 data_process/method_reader_date_feature.py create mode 100644 example_method_reader_date_feature.py create mode 100644 example_method_reader_date_process.py diff --git a/data_process/__pycache__/method_reader_date_feature.cpython-39.pyc b/data_process/__pycache__/method_reader_date_feature.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..20dfd1fba2892c0e702c69048fb1fbf7d5e60f48 GIT binary patch literal 3498 zcmds3?T;J98K2pmeX)J#I4?wmE5S4&#I3kHD3uV3s!E0Q%f*Ta0>A;f9nrfhAYK~2a8)6Z>=w0LKai@ZEmes6e~kK}67l8oClskspP5}dc6#&=s4YMH z%+Aa+ViCb7y7i~lKMo`Gm2Av@bZGn#e(`xQ6j2-?M?SRxw>3v=>yD1I z_rxKp-*60g>Ves|91Ei#BTA^Tji|AuIX1eELo4}3(TX8cOQUd_ICcZ_xXo+e)0b8o1g7pzcIeDGye6b4Lq|g z>C2t{2!8QtFbNvsL>u8ga`iqMk`V&W0MAsOrT)3reGrC@-@Z2f{k!A$cCuxr3)E}2 zu!5-7^23%>Xt87se8z?Cx}n!*t}9I03vZ6PLF7@lt@iCUqOj?=#NvGOcs8cvahRJh zJ{eZI|BXEPm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Q*l97gU7n^mNPEwz4zAmvyU<&-2P~L|N8H4-+1%Z-$#2tzh19lF7GzA zvYV@>OEam^59bqD4LfK42ZJEzoM@tlk=3!AXx?adwwwCBCp9=wqhUuF8HGOk{5KDn#vd8#eoDgGXkzazcazQ%HDPZ z3b|Iqdro<}b*SW^{5y!2MQf_KCuIO_u0^Lv#PQU*m zckRW>gsG2Y_njy9|6ZkDD{%|f5JlH*N3;uv?urH1-ROEjUN&2R{){yDQj_vj{UK{lxkM}v(Z)ox&GO-LrM$#tPp!Zof`>4ZUI!F1i?7Q! pS`>3B5W 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) + } \ No newline at end of file diff --git a/example_method_reader_date_feature.py b/example_method_reader_date_feature.py new file mode 100644 index 0000000..5718f38 --- /dev/null +++ b/example_method_reader_date_feature.py @@ -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) \ No newline at end of file diff --git a/example_method_reader_date_process.py b/example_method_reader_date_process.py new file mode 100644 index 0000000..4f11c7c --- /dev/null +++ b/example_method_reader_date_process.py @@ -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) \ No newline at end of file