17
17
from skmatter .decomposition import _BasePCov
18
18
from skmatter .utils import check_cl_fit
19
19
from skmatter .preprocessing import StandardFlexibleScaler
20
+ import warnings
20
21
21
22
22
23
class PCovC (LinearClassifierMixin , _BasePCov ):
@@ -124,7 +125,7 @@ class PCovC(LinearClassifierMixin, _BasePCov):
124
125
If None, ``sklearn.linear_model.LogisticRegression()``
125
126
is used as the classifier.
126
127
127
- scale_z: bool, default=True
128
+ scale_z: bool, default=False
128
129
Whether to scale Z prior to eigendecomposition.
129
130
130
131
iterated_power : int or 'auto', default='auto'
@@ -147,6 +148,14 @@ class PCovC(LinearClassifierMixin, _BasePCov):
147
148
Tolerance for singular values computed by svd_solver == 'arpack'.
148
149
Must be of range [0.0, infinity).
149
150
151
+ z_mean_tol: float, default=1e-12
152
+ Tolerance for the column means of Z.
153
+ Must be of range [0.0, infinity).
154
+
155
+ z_var_tol: float, default=1.5
156
+ Tolerance for the column variances of Z.
157
+ Must be of range [0.0, infinity).
158
+
150
159
space: {'feature', 'sample', 'auto'}, default='auto'
151
160
whether to compute the PCovC in ``sample`` or ``feature`` space.
152
161
The default is equal to ``sample`` when :math:`{n_{samples} < n_{features}}`
@@ -212,9 +221,11 @@ def __init__(
212
221
n_components = None ,
213
222
svd_solver = "auto" ,
214
223
tol = 1e-12 ,
224
+ z_mean_tol = 1e-12 ,
225
+ z_var_tol = 1.5 ,
215
226
space = "auto" ,
216
227
classifier = None ,
217
- scale_z = True ,
228
+ scale_z = False ,
218
229
iterated_power = "auto" ,
219
230
random_state = None ,
220
231
whiten = False ,
@@ -231,6 +242,8 @@ def __init__(
231
242
)
232
243
self .classifier = classifier
233
244
self .scale_z = scale_z
245
+ self .z_mean_tol = z_mean_tol
246
+ self .z_var_tol = z_var_tol
234
247
235
248
def fit (self , X , Y , W = None ):
236
249
r"""Fit the model with X and Y.
@@ -312,6 +325,23 @@ def fit(self, X, Y, W=None):
312
325
Z = z_scaler .transform (Z )
313
326
W /= z_scaler .scale_ .reshape (1 , - 1 )
314
327
328
+ self .z_means_ = np .mean (Z , axis = 0 )
329
+ self .z_vars_ = np .var (Z , axis = 0 )
330
+
331
+ if np .max (np .abs (self .z_means_ )) > self .z_mean_tol :
332
+ warnings .warn (
333
+ "This class does not automatically center Z, and the column means "
334
+ "of Z are greater than the supplied tolerance. We recommend scaling "
335
+ "Z (and the weights) by setting `scale_z=True`."
336
+ )
337
+
338
+ if np .max (self .z_vars_ ) > self .z_var_tol :
339
+ warnings .warn (
340
+ "This class does not automatically scale Z, and the column variances "
341
+ "of Z are greater than the supplied tolerance. We recommend scaling "
342
+ "Z (and the weights) by setting `scale_z=True`."
343
+ )
344
+
315
345
if self .space_ == "feature" :
316
346
self ._fit_feature_space (X , Y , Z )
317
347
else :
0 commit comments