Reading a graph
Evaluate functions, compare growth rates and read a loss curve without confusing inputs and outputs.
THE IDEA
A graph is a table that never ends
A graph draws every pair (input, output) as a point. The horizontal axis holds the input x. The vertical axis holds the output f(x). To read a value, find the input on the bottom, go straight up to the curve, then straight across to the side. That height is the output. Nothing in the picture says the output must grow when x grows: the curve goes wherever the rule sends it.
Rising between these two points: the output went up.
Orange dot: the probe. Purple dot and dashed line: the point one gap to the right and the straight line through both. Green rings: where the curve meets the axes.
Three things you can read off a graph
- A value: the height of the curve above a chosen x. For the valley curve, the height at x = 4 is 0.5·16 − 4 − 1.5 = 2.5.
- Where it crosses the axes: the vertical crossing is f(0), the output when the input is 0. A horizontal crossing is an input whose output is 0.
- Its direction: the slope between two points is rise over run, (change in output) / (change in input). Positive slope: rising. Negative slope: falling. Slope 0: level.
For a straight line the slope is the same everywhere. For a curve it changes from place to place, which is why we say "between these two points". A line is written y = m·x + b, where m is the slope and b the height at x = 0.
Predict first. A line passes through (0, 3) and (2, −1). What is its slope?
The common mistake: reading the shape as a trend
Beginners often assume "moving right means going up". On the hill-and-valley curve, between x ≈ −1.4 and x ≈ 1.4 the output falls while the input rises. Another trap: reading a height off the wrong axis, or mixing up "the output is 0" (a horizontal crossing) with "the input is 0" (a vertical crossing). Say the question out loud before you read: which quantity am I given, and which one am I looking for?
Chapter context
A function maps an input to an output under a stated rule. Graphs let us see the same rule at many inputs; formulas let us calculate a particular output exactly. Both views should describe the same quantity and units.
TRY IT YOURSELF
Part 1. Do it on the plot
The orange dashed curve is the target. Read two numbers off it, then shape your blue curve y = a·x² + m·x + b until it lies exactly on top.
The probe line is only there to help your eye. The target's numbers are not shown on purpose: read them off the grid.
- To do: Read the dashed target curve: what is its height at x = 4? Type it in the box
- To do: The target crosses the horizontal axis twice. Type the x of the crossing on the right
- To do: Make your curve cross the vertical axis where the target does (same height at x = 0)
- To do: Turn your curve into a straight line that falls 2 for every 1 step right and passes through (0, 3)
- To do: Edit a, m and b until your curve lies exactly on the target
Part 2. Do it in code
- Write slope(p, q) for two points p = (x1, y1) and q = (x2, y2): rise over run. If the points are directly above each other (same x), raise ValueError, since there is no single slope.
- Write intercept(p, q): the height where the straight line through the two points crosses the vertical axis (x = 0).
- Write crossing_x(m, b): the x where the line y = m*x + b crosses the horizontal axis, or None if the line is flat (m == 0).
Stuck, or something not working? You can come back to it any time.
CHECK YOUR UNDERSTANDING
Can a curve go down as x increases?
Chapter reference: math, worked example & code
This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.
Math and notation
For the illustrative loss:
Theta is a tunable scalar, 1.2 is the target, and L is a nonnegative output. An exponent and its logarithm undo each other only on their valid domains.
Worked example
Evaluate L(0)=1.44, L(2)=0.64 and L(1.2)=0. The parameter 2 gives a larger input than 0 but a smaller loss. Squaring makes positive and negative distances contribute the same penalty. This is a synthetic landscape, not a claim that real models have one simple valley.
Reference code
The following example uses the Python standard library and does not call a remote service.
from math import isclose, log2
loss = lambda theta: (theta - 1.2) ** 2
assert isclose(loss(0), 1.44)
assert isclose(loss(2), 0.64)
assert loss(1.2) == 0
assert log2(8) == 3
assert sum(i*i for i in range(1, 4)) == 14
Python examples are provided for study and local execution; this page does not execute Python.
Common mistakes
The output of a loss function is not its input parameter. Larger inputs do not always produce larger outputs. Logarithms require an explicit base when comparing information quantities.