Skip to content

Commit 2e28a48

Browse files
committed
wip: multitask
1 parent 467c48a commit 2e28a48

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

examples/multitask_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
mt = MultiTaskEstimator(
1616
estimator=MultiTaskLassoCV(alphas=np.logspace(-3, 3, 7)),
17-
output_types=n*['binary'])
17+
output_types=n//2*['binary']+n//2*['continuous'])
1818

1919
mt.fit(X, Y)
2020
print(mt.score(X, Y))

stlearn/multitask.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ def predict(self, X):
6565
6666
Returns
6767
-------
68-
Ypred : array, shape = (n_samples, n_outputs)
68+
Y_pred : array, shape = (n_samples, n_outputs)
6969
Predicted outputs per sample.
7070
"""
7171
# predict multiple outputs
72-
Ypred = self._decision_function(X)
72+
Y_pred = self._decision_function(X)
7373
for i in range(self.n_outputs):
7474
if self.output_types[i] == 'binary':
7575
# binarize classification results
76-
labels = np.zeros(Ypred[:, i].shape)
77-
labels[Ypred[:, i] >= 0.5] = 1
78-
Ypred[:, i] = labels
79-
return Ypred
76+
labels = np.zeros(Y_pred[:, i].shape)
77+
labels[Y_pred[:, i] >= 0.5] = 1
78+
Y_pred[:, i] = labels
79+
return Y_pred
8080

8181
def score(self, X, Y):
8282
"""Returns accuracy for each outputs.
@@ -89,20 +89,20 @@ def score(self, X, Y):
8989
X : array-like, shape = (n_samples, n_features)
9090
Sample matrix.
9191
92-
y : array-like, shape = (n_samples) or (n_samples, n_outputs)
92+
Y : array-like, shape = (n_samples, n_outputs)
9393
True labels for X.
9494
9595
Returns
9696
-------
9797
score : list of float, shape (n_outputs,)
98-
Mean accuracy of self.predict(X) wrt. Y.
98+
Accuracy of self.predict(X) wrt. Y.
9999
"""
100-
Ypred = self.predict(X)
100+
Y_pred = self.predict(X)
101101
scores = np.empty((self.n_outputs))
102102
for i in range(self.n_outputs):
103103
# accuracy_score for classification
104104
if self.output_types[i] == 'binary':
105-
scores[i] = accuracy_score(Y[:, i], Ypred[:, i])
105+
scores[i] = accuracy_score(Y[:, i], Y_pred[:, i])
106106
# r2_score for regression
107107
elif self.output_types[i] == 'continuous':
108108
scores[i] = r2_score(Y[:, i], Y_pred[:, i])

0 commit comments

Comments
 (0)