Skip to content

Commit 4b7da27

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 5f1cc20f7dfb4b19f026a5fb062c2ce52fa9ddc8
1 parent 942b1ca commit 4b7da27

File tree

1,364 files changed

+4724
-4727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,364 files changed

+4724
-4727
lines changed
Binary file not shown.
Binary file not shown.

dev/_downloads/a0f093cdc82e6c383a734fc9beaf8e24/plot_gradient_boosting_oob.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
======================================
33
Gradient Boosting Out-of-Bag estimates
44
======================================
5-
65
Out-of-bag (OOB) estimates can be a useful heuristic to estimate
76
the "optimal" number of boosting iterations.
87
OOB estimates are almost identical to cross-validation estimates but
@@ -14,15 +13,13 @@
1413
(the so-called out-of-bag examples).
1514
The OOB estimator is a pessimistic estimator of the true
1615
test loss, but remains a fairly good approximation for a small number of trees.
17-
1816
The figure shows the cumulative sum of the negative OOB improvements
1917
as a function of the boosting iteration. As you can see, it tracks the test
2018
loss for the first hundred iterations but then diverges in a
2119
pessimistic way.
2220
The figure also shows the performance of 3-fold cross validation which
2321
usually gives a better estimate of the test loss
2422
but is computationally more demanding.
25-
2623
"""
2724

2825
# Author: Peter Prettenhofer <[email protected]>
@@ -116,13 +113,19 @@ def cv_estimate(n_splits=None):
116113
test_color = list(map(lambda x: x / 256.0, (127, 201, 127)))
117114
cv_color = list(map(lambda x: x / 256.0, (253, 192, 134)))
118115

116+
# line type for the three curves
117+
oob_line = "dashed"
118+
test_line = "solid"
119+
cv_line = "dashdot"
120+
119121
# plot curves and vertical lines for best iterations
120-
plt.plot(x, cumsum, label="OOB loss", color=oob_color)
121-
plt.plot(x, test_score, label="Test loss", color=test_color)
122-
plt.plot(x, cv_score, label="CV loss", color=cv_color)
123-
plt.axvline(x=oob_best_iter, color=oob_color)
124-
plt.axvline(x=test_best_iter, color=test_color)
125-
plt.axvline(x=cv_best_iter, color=cv_color)
122+
plt.figure(figsize=(8, 4.8))
123+
plt.plot(x, cumsum, label="OOB loss", color=oob_color, linestyle=oob_line)
124+
plt.plot(x, test_score, label="Test loss", color=test_color, linestyle=test_line)
125+
plt.plot(x, cv_score, label="CV loss", color=cv_color, linestyle=cv_line)
126+
plt.axvline(x=oob_best_iter, color=oob_color, linestyle=oob_line)
127+
plt.axvline(x=test_best_iter, color=test_color, linestyle=test_line)
128+
plt.axvline(x=cv_best_iter, color=cv_color, linestyle=cv_line)
126129

127130
# add three vertical lines to xticks
128131
xticks = plt.xticks()
@@ -133,9 +136,9 @@ def cv_estimate(n_splits=None):
133136
ind = np.argsort(xticks_pos)
134137
xticks_pos = xticks_pos[ind]
135138
xticks_label = xticks_label[ind]
136-
plt.xticks(xticks_pos, xticks_label)
139+
plt.xticks(xticks_pos, xticks_label, rotation=90)
137140

138-
plt.legend(loc="upper right")
141+
plt.legend(loc="upper center")
139142
plt.ylabel("normalized loss")
140143
plt.xlabel("number of iterations")
141144

0 commit comments

Comments
 (0)