Concepts / Gradient Boosting Classifiers

Gradient Boosting Classifiers

Suppose you have fitted a gradient boosting model to a two-dimensional toy dataset and want to see what it has learned.

  • Programming

A Question a Single Plot Can Answer Two Ways

Suppose you have fitted a gradient boosting model to a two-dimensional toy dataset and want to see what it has learned. The most familiar picture is a single line that separates the region predicted as one class from the region predicted as the other. That line is useful, but it answers only one question. It tells you where the predicted outcome changes, and nothing about how sure the classifier is at any particular location.

This article works from a plot that answers both questions at once. Before reading any further, keep one question in mind: what extra information does the colored view give that a boundary line alone cannot? You will return to that question at the end of the article.

What a Classifier Assigns to Each Point

A classifier assigns each point in the input plane to a class. Imagine every location in the two-dimensional plane receiving a label. Some locations get the first class, others get the second, and the places where the label switches form the boundary between the classes. Drawing only that boundary tells you where the predicted outcome changes. It does not tell you how strongly the classifier holds any of those predictions.

What do you think happens?

Two points lie on the same side of the boundary. One sits right at the edge of the line and the other sits deep inside its region. What does a boundary-only plot tell you about the difference between them?

  • The boundary-only plot shows that the deep point is more certain than the edge point

  • The boundary-only plot gives both points the same label, and nothing in it separates how sure the classifier is about each

  • The boundary-only plot shows that the edge point is misclassified

Reveal answer
Answer:

The boundary-only plot gives both points the same label, and nothing in it separates how sure the classifier is about each.

The boundary panel answers a categorical question: for each location, which class does the model predict? Two points on the same side receive the same label from this panel, even if one lies at the edge and the other is deep inside its region. The boundary panel does not show how strongly the model holds that prediction.

Reading the Boundary Panel

The left panel of the figure shows the decision boundary, which is the boundary between the two classes. Read it as a map of predicted outcomes. Each location in the plane belongs to one predicted class, and the line marks where that assignment flips. If you want to know which class the model predicts for a given spot, this is the panel to read.

The example uses training points drawn as circles and test points drawn as triangles. Both kinds of point sit on top of the same boundary, so you can check whether the learned line separates the classes where the data actually lies. The boundary panel is the place to check that separation directly.

Reading the Decision Function Panel

The right panel shows the decision function for all points in the plane, colored according to its values. The decision function encodes not only the predicted outcome but also how certain the classifier is. Where the function is strongly positive or strongly negative, the model leans firmly toward one class. Where the value is close to the middle of its range, the model is less decisive. Because the colors vary continuously across the plane, the panel does not split into two flat regions the way the boundary panel does.

The colorbar is the key to reading this panel. The colorbar takes its values from the object returned by the plotting helper, so it supplies the scale that maps each color to a value of the decision function. Without the colorbar you can see that one area is colored differently from another, but you cannot tell how far apart their scores are. With it, you can compare how strongly one area leans toward a class against another area.

Predicted classwhich class at eachlocationDecision functionvalue at every point in theplaneBoundary linewhere the label changesColorbar scalemaps colors to score values
The two panels of the same figure answer different questions. The boundary panel gives a categorical answer for each location, while the decision function panel gives a continuous score that also carries certainty.

Comparing Two Points Using Both Panels

Worked example

Locating a point on both panels

Two test points lie on the same side of the boundary. Point P sits just next to the boundary line. Point Q sits well inside its region. Use the two panels to describe what each one tells you.

  1. 1
    Check the boundary panel

    Find P and Q on the left panel. Both lie on the same side of the line, so both receive the same predicted class. The boundary panel alone cannot separate them.

  2. 2
    Check the decision function panel

    Find P and Q on the right panel. P sits in a region whose color is close to the middle of the scale, which indicates a weak lean toward its class. Q sits in a region with a strongly saturated color, which indicates a firm lean.

  3. 3
    Compare the two readings

    Both points share a predicted class, but the right panel shows that the classifier is much more certain about Q than about P. This is the extra information the colored view provides.

Result

The boundary panel tells you that P and Q share a class. The decision function panel tells you that Q is held with more confidence than P.

Why a Combined View Hides the Boundary

It is tempting to draw the boundary lines on top of the certainty color map so that everything appears in one picture. This often backfires. A certainty color map fills the whole plane with color, and a boundary line drawn over a busy color gradient can blend into the surrounding shades. The line that was the most important feature of the plot becomes the hardest thing to see.

Boundary linesdrawn over the color mapBoundary panelboundary read on its ownCertainty color mapfills the whole planeDecision functionpanelcertainty read on its own
Overlaying boundary lines on the certainty map makes the boundary hard to see, while placing the two views in separate panels keeps each one readable.

Separate panels fix the problem because each view keeps its own visual space. To find the boundary, read the left panel directly. To judge certainty, read the right panel and its colorbar. The two readings are then linked by location: the same point in the plane appears at the same position in both panels.

Tracing a Plot Back to Its Code

When a two-panel plot looks wrong, the cause is usually one specific line in the plotting code rather than the whole script. The result travels from the code to the screen along a path. The boundary and the score map each depend on particular objects and arguments, so a change to one of them changes only that part of the figure.

The plotting snippet assumes that a gradient boosting model named gbrt has already been fitted, and that 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, so it will only run inside that setup. If the figure fails or looks different from the description, first confirm that these objects exist and hold the data you expect.

Once the setup is confirmed, locate the colorbar line. The colorbar takes its values from the object returned by the plotting helper that draws the decision function. If the colorbar shows an unexpected scale, the line that attaches it to that returned object is the place to look. Changing which object the colorbar is attached to changes the scale shown beside the right panel, while the colors themselves come from the decision function values.

Mistakes Beginners Make When Reading the Plot

  • Common mistake

    Treating the colored panel as the boundary

    Why it fails

    The decision function panel shows a continuous score across the whole plane, not the line where the predicted class changes.

    Do this instead

    Read the left panel to locate the boundary directly.

  • Common mistake

    Reading color intensity without the colorbar

    Why it fails

    Without the colorbar, you cannot tell how far apart two colors are in value, so comparing certainty across regions becomes guesswork.

    Do this instead

    Use the colorbar as the scale for the decision function before comparing areas.

  • Common mistake

    Assuming a boundary drawn over the color map is still clear

    Why it fails

    A boundary line blended into a busy gradient can disappear, which hides the most important feature of the plot.

    Do this instead

    Read the boundary and the certainty map in separate panels.

  • Common mistake

    Blaming the whole script when the figure looks wrong

    Why it fails

    A divergence usually begins at one line, so rewriting everything hides the real cause.

    Do this instead

    Follow the path from code to screen and check the specific argument or object each part depends on.

Practice Reading the Two Panels

EASY

Look at a two-panel figure of a gradient boosting classifier on a two-dimensional dataset. Pick one test point near the decision boundary and one test point far from it. Using only the left panel, state what you can and cannot say about each point. Then use the right panel and its colorbar to state what extra information you gain about the classifier's certainty.

Hints
  • Start with the boundary panel to find which side of the line each point lies on.
  • Use the colorbar to convert a color into a relative score before comparing the two points.
  • A point near the line can share a predicted class with a point far from it while being held with much less certainty.
MEDIUM

Suppose a colleague reports that the colorbar beside the right panel shows the wrong scale, while the boundary panel looks correct. Describe which part of the plotting code you would check first and why, using only what the plot depends on.

Hints
  • The colorbar takes its values from a specific object returned by the plotting helper.
  • Because the boundary panel looks correct, the problem is probably not in the shared setup.

Key Takeaways

  • The decision boundary shows where the predicted class changes, and it is drawn on the left panel of the two-panel figure.
  • The decision function encodes both the predicted outcome and how certain the classifier is, shown across the whole plane on the right panel.
  • The colorbar is the scale for the decision function, so reading it is necessary to compare certainty between areas.
  • A combined view can make the boundary hard to see, so read the left panel to locate the boundary directly.
  • When the figure looks wrong, trace the result back to the specific argument or object it depends on, such as the object that supplies the colorbar.

Related concepts

More concepts starting with G