8000 fix: map labels to {0, 1} · deepatdotnet/scikit-learn@f4bd2ca · GitHub
[go: up one dir, main page]

Skip to content

Commit f4bd2ca

Browse files
pprettlarsmans
authored andcommitted
fix: map labels to {0, 1}
1 parent c656b10 commit f4bd2ca

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

examples/ensemble/plot_gradient_boosting_regularization.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
X, y = datasets.make_hastie_10_2(n_samples=12000, random_state=1)
3535
X = X.astype(np.float32)
3636

37+
# map labels from {-1, 1} to {0, 1}
38+
labels = np.unique(y)
39+
y = np.searchsorted(labels, y)
40+
3741
X_train, X_test = X[:2000], X[2000:]
3842
y_train, y_test = y[:2000], y[2000:]
3943

@@ -62,6 +66,7 @@
6266
test_deviance = np.zeros((params['n_estimators'],), dtype=np.float64)
6367

6468
for i, y_pred in enumerate(clf.staged_decision_function(X_test)):
69+
# clf.loss_ assumes that y_test[i] in {0, 1}
6570
test_deviance[i] = clf.loss_(y_test, y_pred)
6671

6772
pl.plot((np.arange(test_deviance.shape[0]) + 1)[::5], test_deviance[::5],

0 commit comments

Comments
 (0)
0