@@ -53,7 +53,7 @@ class KernelPCovC(LinearClassifierMixin, _BaseKPCov):
53
53
54
54
n_components == n_samples
55
55
56
- n_outputs : int
56
+ n_outputs_ : int
57
57
The number of outputs when ``fit`` is performed.
58
58
59
59
svd_solver : {'auto', 'full', 'arpack', 'randomized'}, default='auto'
@@ -88,8 +88,8 @@ class KernelPCovC(LinearClassifierMixin, _BaseKPCov):
88
88
- ``sklearn.linear_model.Perceptron()``
89
89
90
90
If a pre-fitted classifier is provided, it is used to compute :math:`{\mathbf{Z}}`.
91
- If None and ``n_outputs < 2``, ``sklearn.linear_model.LogisticRegression()`` is used.
92
- If None and ``n_outputs == 2``, ``sklearn.multioutput.MultiOutputClassifier()`` is used.
91
+ If None and ``n_outputs_ < 2``, ``sklearn.linear_model.LogisticRegression()`` is used.
92
+ If None and ``n_outputs_ == 2``, ``sklearn.multioutput.MultiOutputClassifier()`` is used.
93
93
94
94
kernel : {"linear", "poly", "rbf", "sigmoid", "precomputed"} or callable, default="linear"
95
95
Kernel.
@@ -137,7 +137,7 @@ class KernelPCovC(LinearClassifierMixin, _BaseKPCov):
137
137
138
138
Attributes
139
139
----------
140
- n_outputs : int
140
+ n_outputs_ : int
141
141
The number of outputs when ``fit`` is performed.
142
142
143
143
classifier : estimator object
@@ -280,7 +280,7 @@ def fit(self, X, Y, W=None):
280
280
281
281
check_classification_targets (Y )
282
282
self .classes_ = np .unique (Y )
283
- self .n_outputs = 1 if Y .ndim == 1 else Y .shape [1 ]
283
+ self .n_outputs_ = 1 if Y .ndim == 1 else Y .shape [1 ]
284
284
285
285
super ()._set_fit_params (X )
286
286
@@ -311,7 +311,7 @@ def fit(self, X, Y, W=None):
311
311
", or `precomputed`"
312
312
)
313
313
314
- multioutput = self .n_outputs != 1
314
+ multioutput = self .n_outputs_ != 1
315
315
precomputed = self .classifier == "precomputed"
316
316
317
317
if self .classifier is None or precomputed :
@@ -453,10 +453,10 @@ def decision_function(self, X=None, T=None):
453
453
Returns
454
454
-------
455
455
Z : numpy.ndarray, shape (n_samples,) or (n_samples, n_classes), or a list of \
456
- n_outputs such arrays if n_outputs > 1
456
+ n_outputs_ such arrays if n_outputs_ > 1
457
457
Confidence scores. For binary classification, has shape `(n_samples,)`,
458
458
for multiclass classification, has shape `(n_samples, n_classes)`.
459
- If n_outputs > 1, the list can contain arrays with differing shapes
459
+ If n_outputs_ > 1, the list can contain arrays with differing shapes
460
460
depending on the number of classes in each output of Y.
461
461
"""
462
462
check_is_fitted (self , attributes = ["pkz_" , "ptz_" ])
@@ -470,7 +470,7 @@ def decision_function(self, X=None, T=None):
470
470
if self .center :
471
471
K = self .centerer_ .transform (K )
472
472
473
- if self .n_outputs == 1 :
473
+ if self .n_outputs_ == 1 :
474
474
# Or self.classifier_.decision_function(K @ self.pkt_)
475
475
return K @ self .pkz_ + self .classifier_ .intercept_
476
476
else :
@@ -482,11 +482,22 @@ def decision_function(self, X=None, T=None):
482
482
else :
483
483
T = check_array (T )
484
484
485
- if self .n_outputs == 1 :
485
+ if self .n_outputs_ == 1 :
486
486
T @ self .ptz_ + self .classifier_ .intercept_
487
487
else :
488
488
return [
489
489
est_ .decision_function (T ) for est_ in self .classifier_ .estimators_
490
490
]
491
491
492
- #TODO: add MultiOutputClassifier's score function for KPCovC to allow for multiclass-multioutput case
492
+ def score (self , X , y ):
493
+
494
+ # accuracy_score will handle everything but multiclass-multilabel
495
+ if self .n_outputs_ > 1 and len (self .classes_ ) > 2 :
496
+ y_pred = self .predict (X )
497
+ return np .mean (np .all (y == y_pred , axis = 1 ))
498
+
499
+ else :
500
+ return super ().score (X , y )
501
+
502
+ # Inherit the docstring from scikit-learn
503
+ score .__doc__ = LinearClassifierMixin .score .__doc__
0 commit comments