@@ -33,6 +33,18 @@ def __init__(self, estimator=None,
33
33
self .n_outputs = len (self .output_types )
34
34
35
35
def fit (self , X , Y ):
36
+ """Fit estimator to the given training data and all outputs.
37
+
38
+ Parameters
39
+ ----------
40
+ X : {array-like, sparse-matrix}, shape (n_samples, n_features)
41
+ Training vector, where n_samples is the number of samples and
42
+ n_features is the number of features.
43
+
44
+ Y : array-like, shape (n_samples, n_outputs)
45
+ Target matrix relative to X.
46
+ """
47
+
36
48
if Y .shape [1 ] != self .n_outputs :
37
49
raise ValueError ('Y columns=%u whereas n_outputs=%u'
38
50
% (Y .shape [1 ], self .output_types ))
@@ -44,6 +56,18 @@ def _decision_function(self, X):
44
56
return self .estimator ._decision_function (X )
45
57
46
58
def predict (self , X ):
59
+ """Predict outputs for samples in X.
60
+
61
+ Parameters
62
+ ----------
63
+ X : {array-like, sparse matrix}, shape = (n_samples, n_features)
64
+ Sample matrix.
65
+
66
+ Returns
67
+ -------
68
+ Ypred : array, shape = (n_samples, n_outputs)
69
+ Predicted outputs per sample.
70
+ """
47
71
# predict multiple outputs
48
72
Ypred = self ._decision_function (X )
49
73
for i in range (self .n_outputs ):
@@ -63,7 +87,7 @@ def score(self, X, Y):
63
87
Parameters
64
88
----------
65
89
X : array-like, shape = (n_samples, n_features)
66
- The multi-input samples .
90
+ Sample matrix .
67
91
68
92
y : array-like, shape = (n_samples) or (n_samples, n_outputs)
69
93
True labels for X.
@@ -73,13 +97,13 @@ def score(self, X, Y):
73
97
score : list of float, shape (n_outputs,)
74
98
Mean accuracy of self.predict(X) wrt. Y.
75
99
"""
76
- # predict multiple outputs
77
- # accuracy for regression and classification
78
100
Ypred = self .predict (X )
79
101
scores = np .empty ((self .n_outputs ))
80
102
for i in range (self .n_outputs ):
103
+ # accuracy_score for classification
81
104
if self .output_types [i ] == 'binary' :
82
105
scores [i ] = accuracy_score (Y [:, i ], Ypred [:, i ])
106
+ # r2_score for regression
83
107
elif self .output_types [i ] == 'continuous' :
84
108
scores [i ] = r2_score (Y [:, i ], Y_pred [:, i ])
85
109
return scores
0 commit comments