metric_entity.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: yq
  4. @time: 2024/11/1
  5. @desc: 常用指标实体集合
  6. """
  7. from typing import Union
  8. import pandas as pd
  9. from commom import f_format_float
  10. class MetricTrainEntity():
  11. """
  12. 模型训练结果指标类
  13. """
  14. def __init__(self, train_auc: float, train_ks: float, test_auc: float, test_ks: float,
  15. train_perf_image_path: str = None, test_perf_image_path: str = None):
  16. self._train_auc = f_format_float(train_auc)
  17. self._train_ks = f_format_float(train_ks)
  18. self._train_perf_image_path = train_perf_image_path
  19. self._test_auc = f_format_float(test_auc)
  20. self._test_ks = f_format_float(test_ks)
  21. self._test_perf_image_path = test_perf_image_path
  22. def __str__(self):
  23. return f"train_auc:{self._train_auc} train_ks:{self._train_ks}\ntest_auc:{self._test_auc} test_ks:{self._test_ks}"
  24. @property
  25. def train_auc(self):
  26. return self._train_auc
  27. @property
  28. def train_ks(self):
  29. return self._train_ks
  30. @property
  31. def test_auc(self):
  32. return self._test_auc
  33. @property
  34. def test_ks(self):
  35. return self._test_ks
  36. class MetricFucEntity():
  37. """
  38. 指标计算函数结果类
  39. """
  40. def __init__(self, table: pd.DataFrame = None, value: str = None, image_path: Union[str, list] = None,
  41. table_font_size=12, table_autofit=False, table_cell_width=None, image_size: int = 6):
  42. self._table = table
  43. self._table_font_size = table_font_size
  44. self._table_cell_width= table_cell_width
  45. self._table_autofit = table_autofit
  46. self._value = value
  47. self._image_path = image_path
  48. self._image_size = image_size
  49. @property
  50. def table_cell_width(self):
  51. return self._table_cell_width
  52. @property
  53. def table_autofit(self):
  54. return self._table_autofit
  55. @property
  56. def table_font_size(self):
  57. return self._table_font_size
  58. @property
  59. def table(self) -> pd.DataFrame:
  60. return self._table
  61. @property
  62. def value(self):
  63. return self._value
  64. @property
  65. def image_path(self):
  66. return self._image_path
  67. @property
  68. def image_size(self):
  69. return self._image_size
  70. if __name__ == "__main__":
  71. pass