statistic_adapter.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright 2019 The FATE Authors. All Rights Reserved.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. from federatedml.feature.feature_selection.model_adapter import isometric_model
  18. from federatedml.feature.feature_selection.model_adapter.adapter_base import BaseAdapter
  19. class StatisticAdapter(BaseAdapter):
  20. def convert(self, model_meta, model_param):
  21. result = isometric_model.IsometricModel()
  22. self_values = model_param.self_values
  23. for value_obj in list(self_values.results):
  24. metric_name = value_obj.value_name
  25. values = list(value_obj.values)
  26. col_names = list(value_obj.col_names)
  27. if len(values) != len(col_names):
  28. raise ValueError(f"The length of values are not equal to the length"
  29. f" of col_names with metric_name: {metric_name}")
  30. metric_info = isometric_model.SingleMetricInfo(values, col_names)
  31. result.add_metric_value(metric_name, metric_info)
  32. return result