We've seen that functions are rules that take an input and produce an output. While writing them down mathematically like f(x)=2x+1 is precise, it's often helpful to see what the function is doing. That's where graphs come in. Visualizing functions helps build intuition about their behavior, which is essential as we move towards understanding change and optimization.
The Coordinate Plane: Our Canvas
To draw a function, we typically use a standard two-dimensional coordinate system, often called the Cartesian plane. You've likely seen this before:
- A horizontal line called the x-axis. This axis represents the input values to our function.
- A vertical line called the y-axis. This axis represents the output values, f(x), that the function produces.
- These axes intersect at a point called the origin, where both x and y are zero, denoted as (0,0).
Any point on this plane can be uniquely identified by a pair of numbers (x,y), representing its horizontal and vertical position, respectively.
Plotting Function Points
A function gives us pairs of (input, output) values. For a function f, each input x corresponds to an output y=f(x). We can represent this pair as a point (x,f(x)) on the coordinate plane.
Let's take our simple linear function example: f(x)=2x+1.
- If the input is x=0, the output is f(0)=2(0)+1=1. This gives us the point (0,1).
- If the input is x=1, the output is f(1)=2(1)+1=3. This gives us the point (1,3).
- If the input is x=−1, the output is f(−1)=2(−1)+1=−1. This gives us the point (−1,−1).
We can calculate as many of these points as we like.
From Points to Pictures: The Graph
The graph of a function is simply the set of all possible points (x,f(x)) plotted on the coordinate plane. When we connect these points, they usually form a line or a curve that visually represents the function's behavior across a range of inputs.
For our linear function f(x)=2x+1, if we plot the points we calculated and connect them, we get a straight line.
The graph of the linear function f(x)=2x+1 is a straight line. The slope of the line visually represents how quickly the output changes for a given change in the input.
Now, let's consider a slightly different function, a quadratic one: g(x)=x2.
- If x=0, g(0)=02=0. Point: (0,0).
- If x=1, g(1)=12=1. Point: (1,1).
- If x=−1, g(−1)=(−1)2=1. Point: (−1,1).
- If x=2, g(2)=22=4. Point: (2,4).
- If x=−2, g(−2)=(−2)2=4. Point: (−2,4).
Plotting these points and connecting them results in a curve called a parabola.
The graph of the quadratic function g(x)=x2 is a parabola. Notice how the steepness of the curve changes. It decreases as x approaches 0 from the left, is flat at x=0, and increases as x moves away from 0 to the right.
Comparing the two graphs, you can see the difference in how the functions behave. The linear function changes at a constant rate (the line has a constant slope). The quadratic function's rate of change is itself changing (the curve's steepness varies). This visual difference hints at the concept of derivatives we'll explore soon.
Why Visualize in Machine Learning?
Graphs are incredibly useful tools for understanding. In machine learning:
- Model Representation: Simple models can sometimes be visualized. For example, a linear regression model in two dimensions (one input feature, one output prediction) is represented by a straight line, similar to our f(x)=2x+1 example. Visualizing this helps understand how the model makes predictions.
- Understanding Cost Functions: Machine learning training often involves minimizing a "cost" or "loss" function. This function measures how bad our model's predictions are. Often, the cost is a function of the model's parameters (like the m and b in y=mx+b). While cost functions in real ML problems have many inputs (parameters), we can visualize simplified versions (with one or two parameters) as curves or surfaces. The goal of training is often to find the lowest point on this graph, representing the parameter values that give the minimum error. Seeing the graph helps understand what "minimization" means.
- Building Intuition: Even when we deal with functions of many variables (which are impossible to visualize directly in 2D or 3D), the intuition gained from simple 1D and 2D graphs carries over. Concepts like "slope," "steepness," and "minimum points" have analogous meanings in higher dimensions, and understanding the visual representation makes these abstract ideas more concrete.
Seeing the shape of a function through its graph provides immediate insights into its properties. As we move into calculus, we'll develop tools to precisely measure characteristics like the steepness (slope) at any point on these graphs, which is fundamental to how many machine learning algorithms learn and optimize.