11import time
22from enum import IntEnum
3+ from collections import OrderedDict
34
45import numpy as np
56
1213from AnyQt .QtCore import Qt , QEvent , QRectF , QSize
1314
1415from Orange .data import Table , Domain
16+ from Orange .data .util import nan_min , nan_max , nan_average , unique
1517from Orange .classification import Model
1618from Orange .classification .naive_bayes import NaiveBayesModel
1719from Orange .classification .logistic_regression import \
@@ -865,11 +867,13 @@ def calculate_log_reg_coefficients(self):
865867 self .log_reg_coeffs = [coeffs [:, ranges [i ]] for i in range (len (attrs ))]
866868 self .log_reg_coeffs_orig = self .log_reg_coeffs .copy ()
867869
868- for i in range (len (self .log_reg_coeffs )):
870+ min_values = nan_min (self .data .X , axis = 0 )
871+ max_values = nan_max (self .data .X , axis = 0 )
872+
873+ for i , min_t , max_t in zip (range (len (self .log_reg_coeffs )),
874+ min_values , max_values ):
869875 if self .log_reg_coeffs [i ].shape [1 ] == 1 :
870876 coef = self .log_reg_coeffs [i ]
871- min_t = np .nanmin (self .data .X , axis = 0 )[i ]
872- max_t = np .nanmax (self .data .X , axis = 0 )[i ]
873877 self .log_reg_coeffs [i ] = np .hstack ((coef * min_t , coef * max_t ))
874878 self .log_reg_cont_data_extremes .append (
875879 [sorted ([min_t , max_t ], reverse = (c < 0 )) for c in coef ])
@@ -1076,10 +1080,10 @@ def _init_feature_marker_values(self):
10761080 value , feature_val = 0 , None
10771081 if len (self .log_reg_coeffs ):
10781082 if attr .is_discrete :
1079- ind , n = np . unique (self .data .X [:, i ], return_counts = True )
1083+ ind , n = unique (self .data .X [:, i ], return_counts = True )
10801084 feature_val = np .nan_to_num (ind [np .argmax (n )])
10811085 else :
1082- feature_val = np . average (self .data .X [:, i ])
1086+ feature_val = nan_average (self .data .X [:, i ])
10831087 inst_in_dom = instances and attr in instances .domain
10841088 if inst_in_dom and not np .isnan (instances [0 ][attr ]):
10851089 feature_val = instances [0 ][attr ]
@@ -1104,13 +1108,15 @@ def send_report(self):
11041108
11051109 @staticmethod
11061110 def reconstruct_domain (original , preprocessed ):
1107- attrs = []
1111+ # abuse dict to make "in" comparisons faster
1112+ attrs = OrderedDict ()
11081113 for attr in preprocessed .attributes :
11091114 cv = attr ._compute_value .variable ._compute_value
11101115 var = cv .variable if cv else original [attr .name ]
1111- if var in attrs :
1116+ if var in attrs : # the reason for OrderedDict
11121117 continue
1113- attrs .append (var )
1118+ attrs [var ] = None # we only need keys
1119+ attrs = list (attrs .keys ())
11141120 return Domain (attrs , original .class_var , original .metas )
11151121
11161122 @staticmethod
0 commit comments