data_process_config_entity.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: yq
  4. @time: 2024/11/1
  5. @desc: 数据处理配置类
  6. """
  7. import json
  8. import os
  9. from commom import GeneralException
  10. from enums import ResultCodesEnum
  11. from sklearn.model_selection import train_test_split
  12. class DataProcessConfigEntity():
  13. def __init__(self, y_column: str, fill_method: str, split_method: str):
  14. # 定义y变量
  15. self._y_column = y_column
  16. # 缺失值填充方法
  17. self._fill_method = fill_method
  18. # 数据划分方法
  19. self._split_method = split_method
  20. @property
  21. def y_column(self):
  22. return self._y_column
  23. @property
  24. def fill_method(self):
  25. return self._fill_method
  26. @property
  27. def split_method(self):
  28. return self._split_method
  29. @staticmethod
  30. def from_config(config_path: str):
  31. """
  32. 从配置文件生成实体类
  33. """
  34. if os.path.exists(config_path):
  35. with open(config_path, mode="r", encoding="utf-8") as f:
  36. j = json.loads(f.read())
  37. else:
  38. raise GeneralException(ResultCodesEnum.NOT_FOUND, message=f"指配置文件【{config_path}】不存在")
  39. return DataProcessConfigEntity(**j)
  40. if __name__ == "__main__":
  41. pass