psi_adapter.py 795 B

12345678910111213141516171819202122232425
  1. import numpy as np
  2. from federatedml.feature.feature_selection.model_adapter import isometric_model
  3. from federatedml.feature.feature_selection.model_adapter.adapter_base import BaseAdapter
  4. from federatedml.util import consts
  5. class PSIAdapter(BaseAdapter):
  6. def convert(self, model_meta, model_param):
  7. psi_scores = dict(model_param.total_score)
  8. col_names, values = [], []
  9. for name in psi_scores:
  10. col_names.append(name)
  11. values.append(psi_scores[name])
  12. single_info = isometric_model.SingleMetricInfo(
  13. values=np.array(values),
  14. col_names=col_names
  15. )
  16. result = isometric_model.IsometricModel()
  17. result.add_metric_value(metric_name=consts.PSI, metric_info=single_info)
  18. return result