metric_entity.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. image_size: int = 6):
  42. self._table = table
  43. self._value = value
  44. self._image_path = image_path
  45. self._image_size = image_size
  46. @property
  47. def table(self) -> pd.DataFrame:
  48. return self._table
  49. @property
  50. def value(self):
  51. return self._value
  52. @property
  53. def image_path(self):
  54. return self._image_path
  55. @property
  56. def image_size(self):
  57. return self._image_size
  58. if __name__ == "__main__":
  59. pass