Decision Boundary Basics
The decision boundary shows where the predicted class changes, and it is drawn on the left panel of the example figure.
Why One Plot Is Not Enough
A classifier assigns every point in the input plane to a class. If you draw only the line where the predicted class changes, you learn where the predicted outcome switches from one class to the other. You learn nothing about how sure the classifier is at a given location. A point sitting right at the edge of a region and a point sitting deep inside it would look identical to a boundary-only plot, because both receive the same label.
This article works from a plot that answers both questions at once. It places two views side by side. The left view shows the decision boundary. The right view shows a decision function, colored across the whole two-dimensional plane. The example model is a gradient boosting model trained on a two-dimensional toy dataset, where training points appear as circles and test points appear as triangles. Keep one question in mind as you read: what extra information does the colored view give that a boundary line alone cannot?
Tracing Two Points Through the Plot
Imagine two points that both fall on the same side of the boundary. The left panel treats them identically: each gets the label of its region. Now consider where each point sits. One is just inside the edge of its region. The other is far from the edge, well inside its region. Trace each point through the figure in two steps. First, find its region on the left panel and read its label. Second, find its location on the right panel and read the color, which corresponds to a decision function value on the colorbar.
What do you think happens?
Both points get the same predicted class from the left panel. Which one does the right panel show as leaning more strongly toward that class: the point at the edge, or the point deep inside its region?
Reveal answer
The point deep inside its region
The right panel varies continuously across the plane rather than splitting into flat regions, and the colorbar maps its colors to decision function values. A point deep inside a region sits where the decision function is more strongly in favor of that class, while a point near the edge sits where the value is less strongly in favor. The left panel cannot show this difference because it records only the label.
Reading the Two Panels Side by Side
The left panel shows the decision boundary, which is the boundary between the two classes. It answers a categorical question: for each location in the plane, which class does the model predict? The right panel shows the decision function for all points in the plane, colored according to its values. It answers a graded question: how strongly does the model hold its prediction at each location? The figure caption describes the same pairing, with the boundary on the left and the decision function on the right, both for a gradient boosting model on the two-dimensional toy dataset.
Read the two panels as a pair. The left panel tells you where the label switches. The right panel tells you how the strength of the prediction changes as you move across that switch. Because the right panel is continuous rather than made of two flat regions, it carries more information than the boundary alone.
The Colorbar as a Scale
The colorbar is the key to reading the right panel. It maps colors to the values of the decision function, which gives the color scale its meaning. Without it, you could see that one area is colored differently from another but could not tell how far apart their decision function values are. With it, you can compare how strongly one area leans toward a class compared with another area.
In the plotting code, the colorbar takes its values from the object returned by plot_2d_scores. That object is what supplies the scale for the decision function, so the colorbar is tied to that specific returned object rather than to the boundary.
Tracing the Path from Code to Screen
The plotting code is assumed to run after a gradient boosting model named gbrt has already been fitted, and after the arrays X, X_train, X_test, y_train, and y_test exist from earlier in the chapter. The snippet does not create these objects itself, so it only runs inside that setup. When you read the code, do it first, then compare what it produces with the description of the two panels.
When a two-panel plot looks wrong, the cause is usually one specific line rather than the whole script. Trace the path a result takes from the code to the screen, and check each step against what you expected. The first step where the output diverges is where the problem begins. For the colorbar, that means checking the object that plot_2d_scores returns, since the colorbar depends on it. For the boundary, check the inputs the boundary depends on, since the boundary is what the left panel is built to show.
Mistakes Beginners Make with Combined Views
Common mistake Overlaying certainty shading on the boundary and expecting both to stay clear
What it looks likeA plot shades the whole plane by decision function value and draws the boundary line over the same region.
Why it failsA combined view can make the boundary hard to see. The shading competes with the line, so the place where the label switches becomes difficult to locate.
Do this insteadRead the left panel to locate the boundary directly, then read the right panel to judge certainty. When you need both, draw them separately, as the two-panel figure does.
Common mistake Assuming a point on the same side of the boundary has the same certainty
What it looks likeTreating a point just inside the edge and a point deep inside its region as equally confident because the left panel gives them the same label.
Why it failsThe boundary panel records only the predicted class. It does not show how strongly the model holds that prediction.
Do this insteadCheck the right panel at each point. Its continuous values show how strongly the model leans, which the left panel cannot show.
Common mistake Reading the colors without the colorbar
What it looks likeSaying one area is 'more blue' than another and concluding how much more confident the model is.
Why it failsThe colors only have meaning through the scale on the colorbar, which maps colors to decision function values.
Do this insteadUse the colorbar to compare the values of the two areas before drawing any conclusion about strength.
Common mistake Running the plotting snippet on its own
What it looks likeCopying the plotting code into an empty file and expecting the two-panel figure to appear.
Why it failsThe snippet assumes that gbrt has been fitted and that X, X_train, X_test,
y_train, andy_testexist. It does not create them.Do this insteadRun the snippet only inside the setup it assumes, after the model and arrays from earlier in the chapter exist.
Practice Reading a Point
Reading one point across both panels
A test point sits inside the region the left panel labels as the first class, close to the boundary. How do you determine its predicted class and how strongly the model favors that class?
- 1Find the region on the left panel
Locate the point on the boundary panel and note which class region it falls in. That region's label is the predicted class.
- 2Find the same location on the right panel
The right panel shows the decision function across the whole plane, so the same location has a color there.
- 3Map the color to a value with the colorbar
Use the colorbar to convert the color into a decision function value. Because the point is near the boundary, expect a value that leans less strongly than a point deep inside the region.
- 4Combine the two readings
The left panel gives the class and the right panel gives the strength of the lean. Report both, not just the label.
The point's predicted class comes from the left panel. Its strength of preference comes from the colorbar-scaled value on the right panel, and a point near the boundary shows a weaker lean than one deep inside its region.
Two test points are both labeled as the second class on the left panel. Point A lies just across the boundary, close to the edge. Point B lies far from the edge, deep in the same region. Explain how you would use the right panel to tell which prediction is more certain, and say what you would check on the colorbar before drawing that conclusion.
Hints
- Start from what the left panel cannot tell you about the two points.
- Think about what the colorbar maps to, and which point should show the stronger value.
Key Takeaways
- The decision boundary, on the left panel, shows where the predicted class changes, but it records only the label and not how certain the classifier is.
- The right panel shows the decision function across the whole plane, and its continuous colors reveal how strongly the model leans toward a class at each location.
- The colorbar maps colors to decision function values, and in the plotting code it takes its values from the object returned by
plot_2d_scores. - A combined boundary-plus-certainty view can hide the boundary, so read the left panel to locate the boundary directly and use the right panel to judge certainty.