Skip to content

Commit 467c48a

Browse files
committed
wip: docstring
1 parent feb46a0 commit 467c48a

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

stlearn/multitask.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ def __init__(self, estimator=None,
3333
self.n_outputs = len(self.output_types)
3434

3535
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+
3648
if Y.shape[1] != self.n_outputs:
3749
raise ValueError('Y columns=%u whereas n_outputs=%u'
3850
% (Y.shape[1], self.output_types))
@@ -44,6 +56,18 @@ def _decision_function(self, X):
4456
return self.estimator._decision_function(X)
4557

4658
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+
"""
4771
# predict multiple outputs
4872
Ypred = self._decision_function(X)
4973
for i in range(self.n_outputs):
@@ -63,7 +87,7 @@ def score(self, X, Y):
6387
Parameters
6488
----------
6589
X : array-like, shape = (n_samples, n_features)
66-
The multi-input samples.
90+
Sample matrix.
6791
6892
y : array-like, shape = (n_samples) or (n_samples, n_outputs)
6993
True labels for X.
@@ -73,13 +97,13 @@ def score(self, X, Y):
7397
score : list of float, shape (n_outputs,)
7498
Mean accuracy of self.predict(X) wrt. Y.
7599
"""
76-
# predict multiple outputs
77-
# accuracy for regression and classification
78100
Ypred = self.predict(X)
79101
scores = np.empty((self.n_outputs))
80102
for i in range(self.n_outputs):
103+
# accuracy_score for classification
81104
if self.output_types[i] == 'binary':
82105
scores[i] = accuracy_score(Y[:, i], Ypred[:, i])
106+
# r2_score for regression
83107
elif self.output_types[i] == 'continuous':
84108
scores[i] = r2_score(Y[:, i], Y_pred[:, i])
85109
return scores

stlearn/stacking.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ def stack_features(X):
2121
2222
Returns
2323
-------
24-
Xstacked : (n_samples x (n_features*n_sources)) stacked 2d matrix
25-
26-
features_indices : (n_features*n_sources) list of indices
24+
Xstacked : shape = (n_samples, n_features*n_sources) stacked 2d matrix
25+
features_indices : shape = (n_sources, ) list of indices
2726
"""
2827
X_stacked = np.hstack(X)
2928

@@ -36,7 +35,7 @@ def stack_features(X):
3635

3736

3837
def _split_features(X, feature_indices):
39-
"""helper"""
38+
"""Helper"""
4039
return [X[:, fi] for fi in feature_indices]
4140

4241

0 commit comments

Comments
 (0)