Refresher: Functions & Graphs
What a function is (a rule from inputs to outputs), reading and sketching graphs, straight lines and their slope, curves such as x², exponential growth and decay, and logarithms as the reverse of powers.
A function is a rule
A function takes an input and gives exactly one output, following a rule. We write : "f of x equals two x plus one". The input goes in, comes out: , , .
This is exactly the idea of a machine learning model: a function from inputs (a house's size, an image's pixels) to an output (a price, the word "cat"). Training is finding the rule's numbers.
Graphs: pictures of functions
A graph plots every input on the horizontal axis () against its output on the vertical axis (). The point means "when is 3, is 7". Reading a graph means asking: when grows, does grow, shrink, or turn around? How fast?
Straight lines: slope and intercept
The simplest functions are straight lines: .
- is the slope (or gradient): how much changes when increases by 1. Positive slopes go up, negative ones go down, zero is flat.
- is the intercept: the value of when , where the line crosses the vertical axis.
The slope between two points is "rise over run": . Between and the slope is . Linear regression, the first model in machine learning, is finding the best and for some data.
Try it: move a line, then a curve
Change the slope and intercept and watch the line move. Then switch to the other functions and see their shapes.
Interactive: this part runs in your browser.
Curves: squares and other powers
is a U-shaped curve (a parabola): it is never negative, it is lowest at , and it grows faster and faster. Squared errors in ML have this shape, which is why "find the lowest point of a U" is the central job of training. keeps its sign, and grows ever more slowly.
Exponential growth and decay
In an exponential function the input is in the exponent: doubles every time goes up by 1. Exponential growth starts slowly and then explodes (compound interest, viral spread). halves each step: exponential decay (a learning rate schedule that shrinks each epoch). The most important base is the number , giving , written exp(x) in code. It appears in the sigmoid and softmax functions.
Logarithms: the reverse of powers
A logarithm answers "what power do I need?": because , and . The natural log (written log(x) in NumPy) uses base . Logs turn multiplication into addition: . That is why models add up log-probabilities instead of multiplying tiny probabilities. Logs of numbers between 0 and 1 are negative, and . The notation lesson goes further.
Practice: check yourself
Work each question out (on paper, in your head, or in Python), type the answer and press ✔ Check. Fractions like 1/4 are fine. Hints and a worked answer are there when you need them.
Summary
Key words
- function
- a rule that turns each input into one output
- graph
- a picture of inputs (x) against outputs (y)
- slope
- change in y per 1 step in x: rise over run
- intercept
- the value of y when x is 0
- parabola
- the U shape of
- exponential
- the input is the power: ,
- logarithm
- the power needed:
Common mistakes
- Mixing up slope and intercept in .
- Rise over run upside down: it is change in y divided by change in x.
- . Only products split: .
- Taking the log of zero or a negative number: it is undefined.
- Thinking exponential means "fast" from the start: it begins slowly.
Quiz
1. If , what is ?
2. What is the slope between and ?
3. In , where does the line cross the y-axis?
4. What is ?
5. Which grows fastest for large x?