1414from .base import (Distance , DistanceModel , FittedDistance , FittedDistanceModel ,
1515 SklDistance , _orange_to_numpy )
1616
17+
1718class EuclideanRowsModel (FittedDistanceModel ):
1819 """
1920 Model for computation of Euclidean distances between rows.
@@ -23,14 +24,14 @@ class EuclideanRowsModel(FittedDistanceModel):
2324 """
2425 def __init__ (self , attributes , impute , normalize ,
2526 continuous , discrete ,
26- means , vars , dist_missing2_cont ,
27+ means , stdvars , dist_missing2_cont ,
2728 dist_missing_disc , dist_missing2_disc ):
2829 super ().__init__ (attributes , 1 , impute )
2930 self .normalize = normalize
3031 self .continuous = continuous
3132 self .discrete = discrete
3233 self .means = means
33- self .vars = vars
34+ self .vars = stdvars
3435 self .dist_missing2_cont = dist_missing2_cont
3536 self .dist_missing_disc = dist_missing_disc
3637 self .dist_missing2_disc = dist_missing2_disc
@@ -91,11 +92,11 @@ class EuclideanColumnsModel(FittedDistanceModel):
9192 Means are used as offsets for normalization, and two deviations are
9293 used for scaling.
9394 """
94- def __init__ (self , attributes , impute , normalize , means , vars ):
95+ def __init__ (self , attributes , impute , normalize , means , stdvars ):
9596 super ().__init__ (attributes , 0 , impute )
9697 self .normalize = normalize
9798 self .means = means
98- self .vars = vars
99+ self .vars = stdvars
99100
100101 def compute_distances (self , x1 , x2 = None ):
101102 """
@@ -134,6 +135,7 @@ class Euclidean(FittedDistance):
134135 rows_model_type = EuclideanRowsModel
135136
136137 def __new__ (cls , e1 = None , e2 = None , axis = 1 , impute = False , normalize = False ):
138+ # pylint: disable=arguments-differ
137139 return super ().__new__ (cls , e1 , e2 , axis , impute , normalize = normalize )
138140
139141 def get_continuous_stats (self , column ):
@@ -160,9 +162,8 @@ def fit_cols(self, attributes, x, n_vals):
160162 for normalization and imputation.
161163 """
162164 def nowarn (msg , cat , * args , ** kwargs ):
163- if cat is RuntimeWarning and (
164- msg == "Mean of empty slice"
165- or msg == "Degrees of freedom <= 0 for slice" ):
165+ if cat is RuntimeWarning and msg in (
166+ "Mean of empty slice" , "Degrees of freedom <= 0 for slice" ):
166167 if self .normalize :
167168 raise ValueError ("some columns have no defined values" )
168169 else :
@@ -174,11 +175,11 @@ def nowarn(msg, cat, *args, **kwargs):
174175 orig_warn = warnings .warn
175176 with patch ("warnings.warn" , new = nowarn ):
176177 means = np .nanmean (x , axis = 0 )
177- vars = np .nanvar (x , axis = 0 )
178- if self .normalize and not vars .all ():
178+ stdvars = np .nanvar (x , axis = 0 )
179+ if self .normalize and not stdvars .all ():
179180 raise ValueError ("some columns are constant" )
180181 return EuclideanColumnsModel (
181- attributes , self .impute , self .normalize , means , vars )
182+ attributes , self .impute , self .normalize , means , stdvars )
182183
183184
184185class ManhattanRowsModel (FittedDistanceModel ):
@@ -270,6 +271,7 @@ class Manhattan(FittedDistance):
270271 rows_model_type = ManhattanRowsModel
271272
272273 def __new__ (cls , e1 = None , e2 = None , axis = 1 , impute = False , normalize = False ):
274+ # pylint: disable=arguments-differ
273275 return super ().__new__ (cls , e1 , e2 , axis , impute , normalize = normalize )
274276
275277 def get_continuous_stats (self , column ):
@@ -337,6 +339,10 @@ def fit_rows(self, attributes, x, n_vals):
337339
338340 fit_cols = fit_rows
339341
342+ def get_continuous_stats (self , column ):
343+ # Implement an unneeded abstract method to silence pylint
344+ return None
345+
340346 class CosineModel (FittedDistanceModel ):
341347 """Model for computation of cosine distances across rows and columns.
342348 All non-zero discrete values are treated as 1."""
@@ -402,6 +408,7 @@ def _compute_dense(self, x1, x2):
402408 compute distances between rows without missing values, and a slower
403409 loop for those with missing values.
404410 """
411+ # view is false positive, pylint: disable=no-member
405412 nonzeros1 = np .not_equal (x1 , 0 ).view (np .int8 )
406413 if self .axis == 1 :
407414 nans1 = _distance .any_nan_row (x1 )
@@ -421,7 +428,8 @@ def _compute_dense(self, x1, x2):
421428 return _distance .jaccard_cols (
422429 nonzeros1 , x1 , nans1 , self .ps )
423430
424- def _compute_sparse (self , x1 , x2 = None ):
431+ @staticmethod
432+ def _compute_sparse (x1 , x2 = None ):
425433 symmetric = x2 is None
426434 if symmetric :
427435 x2 = x1
@@ -462,6 +470,10 @@ def fit_rows(self, attributes, x, n_vals):
462470
463471 fit_cols = fit_rows
464472
473+ def get_continuous_stats (self , column ):
474+ # Implement an unneeded abstract method to silence pylint
475+ return None
476+
465477
466478class CorrelationDistanceModel (DistanceModel ):
467479 """Helper class for normal and absolute Pearson and Spearman correlation"""
@@ -561,7 +573,7 @@ def _corrcoef2(a, b, axis=0):
561573 numpy.corrcoef
562574 """
563575 a , b = np .atleast_2d (a , b )
564- if not ( axis == 0 or axis == 1 ):
576+ if axis not in ( 0 , 1 ):
565577 raise ValueError ("Invalid axis {} (only 0 or 1 accepted)" .format (axis ))
566578
567579 mean_a = np .mean (a , axis = axis , keepdims = True )
@@ -597,6 +609,7 @@ def _corrcoef2(a, b, axis=0):
597609
598610
599611class CorrelationDistance (Distance ):
612+ # pylint: disable=abstract-method
600613 supports_missing = False
601614
602615
0 commit comments