15
15
16
16
from abc import abstractmethod
17
17
18
+ import numbers
18
19
import numpy as np
19
20
20
21
from joblib import Parallel
27
28
from ._base import _BaseHeterogeneousEnsemble
28
29
from ..preprocessing import LabelEncoder
29
30
from ..utils import Bunch
31
+ from ..utils import check_scalar
30
32
from ..utils .metaestimators import available_if
31
33
from ..utils .validation import check_is_fitted
32
34
from ..utils .multiclass import check_classification_targets
@@ -46,7 +48,7 @@ class _BaseVoting(TransformerMixin, _BaseHeterogeneousEnsemble):
46
48
def _log_message (self , name , idx , total ):
47
49
if not self .verbose :
48
50
return None
49
- return "(%d of %d ) Processing %s" % ( idx , total , name )
51
+ return f"( { idx } of { total } ) Processing { name } "
50
52
51
53
@property
52
54
def _weights_not_none (self ):
@@ -64,11 +66,17 @@ def fit(self, X, y, sample_weight=None):
64
66
"""Get common fit operations."""
65
67
names , clfs = self ._validate_estimators ()
66
68
69
+ check_scalar (
70
+ self .verbose ,
71
+ name = "verbose" ,
72
+ target_type = (numbers .Integral , np .bool_ ),
73
+ min_val = 0 ,
74
+ )
75
+
67
76
if self .weights is not None and len (self .weights ) != len (self .estimators ):
68
77
raise ValueError (
69
- "Number of `estimators` and weights must be equal"
70
- "; got %d weights, %d estimators"
71
- % (len (self .weights ), len (self .estimators ))
78
+ "Number of `estimators` and weights must be equal; got"
79
+ f" { len (self .weights )} weights, { len (self .estimators )} estimators"
72
80
)
73
81
74
82
self .estimators_ = Parallel (n_jobs = self .n_jobs )(
@@ -324,9 +332,15 @@ def fit(self, X, y, sample_weight=None):
324
332
"Multilabel and multi-output classification is not supported."
325
333
)
326
334
335
+ check_scalar (
336
+ self .flatten_transform ,
337
+ name = "flatten_transform" ,
338
+ target_type = (numbers .Integral , np .bool_ ),
339
+ )
340
+
327
341
if self .voting not in ("soft" , "hard" ):
328
342
raise ValueError (
329
- "Voting must be 'soft' or 'hard'; got (voting=%r)" % self .voting
343
+ f "Voting must be 'soft' or 'hard'; got (voting={ self .voting !r } )"
330
344
)
331
345
332
346
self .le_ = LabelEncoder ().fit (y )
0 commit comments