|
1 | 1 | import time |
2 | 2 | from enum import IntEnum |
| 3 | +from collections import OrderedDict |
3 | 4 |
|
4 | 5 | import numpy as np |
5 | 6 |
|
@@ -868,11 +869,13 @@ def calculate_log_reg_coefficients(self): |
868 | 869 | self.log_reg_coeffs = [coeffs[:, ranges[i]] for i in range(len(attrs))] |
869 | 870 | self.log_reg_coeffs_orig = self.log_reg_coeffs.copy() |
870 | 871 |
|
871 | | - for i in range(len(self.log_reg_coeffs)): |
| 872 | + min_values = nanmin(self.data.X, axis=0) |
| 873 | + max_values = nanmax(self.data.X, axis=0) |
| 874 | + |
| 875 | + for i, min_t, max_t in zip(range(len(self.log_reg_coeffs)), |
| 876 | + min_values, max_values): |
872 | 877 | if self.log_reg_coeffs[i].shape[1] == 1: |
873 | 878 | coef = self.log_reg_coeffs[i] |
874 | | - min_t = nanmin(self.data.X, axis=0)[i] |
875 | | - max_t = nanmax(self.data.X, axis=0)[i] |
876 | 879 | self.log_reg_coeffs[i] = np.hstack((coef * min_t, coef * max_t)) |
877 | 880 | self.log_reg_cont_data_extremes.append( |
878 | 881 | [sorted([min_t, max_t], reverse=(c < 0)) for c in coef]) |
@@ -1109,13 +1112,15 @@ def send_report(self): |
1109 | 1112 |
|
1110 | 1113 | @staticmethod |
1111 | 1114 | def reconstruct_domain(original, preprocessed): |
1112 | | - attrs = [] |
| 1115 | + # abuse dict to make "in" comparisons faster |
| 1116 | + attrs = OrderedDict() |
1113 | 1117 | for attr in preprocessed.attributes: |
1114 | 1118 | cv = attr._compute_value.variable._compute_value |
1115 | 1119 | var = cv.variable if cv else original[attr.name] |
1116 | | - if var in attrs: |
| 1120 | + if var in attrs: # the reason for OrderedDict |
1117 | 1121 | continue |
1118 | | - attrs.append(var) |
| 1122 | + attrs[var] = None # we only need keys |
| 1123 | + attrs = list(attrs.keys()) |
1119 | 1124 | return Domain(attrs, original.class_var, original.metas) |
1120 | 1125 |
|
1121 | 1126 | @staticmethod |
|
0 commit comments