What is a Vector? The True Building Blocks of Machine Learning
What is a Vector? (From a Developer's Perspective)
As a developer, you use arrays and lists every single day. But what if I told you that a simple list, like [3, 4]
, is the single most important object in all of machine learning? We call it a vector, and today, we're going to decode what that really means.
This is the first post in our foundational series on the math behind machine learning. Watch the video below for a quick visual introduction, then read on for a deeper dive into the code and concepts.
From a Point to an Arrow
Let's take our list, [3, 4]
. On a simple 2D graph, this represents a point: 3 units to the right on the x-axis, and 4 units up on the y-axis.
But when we treat this as a vector, it’s not just a point. We think of it as an arrow starting from the origin at (0,0)
and pointing directly to that point. This is the key difference.
The Key Properties: Magnitude and Direction
This "arrow" has two key properties that a plain list doesn't have:
Magnitude
Magnitude is the length of the vector’s arrow. For a vector v = [x, y]
, you can calculate it using the Pythagorean theorem:
For our vector v = [3, 4]
, the length is 5 units. This formula comes directly from the Pythagorean theorem, and we'll do a full deep dive into the intuition and the code behind this in our next post!
Direction
Direction is the angle the arrow makes, usually with the x-axis. It tells us where the vector is pointing.
Why Vectors Matter for Developers
So why do we suddenly care? Because in machine learning, vectors turn raw data into something models can understand. They are the universal language of AI:
- A pixel’s RGB values become a vector:
[255, 128, 0]
. - A user’s preferences become a vector:
[5, 2, 8]
. - Words become high-dimensional vectors (embeddings) for models like ChatGPT.
Here’s how you can represent a vector and calculate its magnitude in Python using NumPy:
import numpy as np
v = np.array([3, 4])
magnitude = np.linalg.norm(v)
print(f"Vector: {v}, Magnitude: {magnitude}")
# Output: Vector: [3 4], Magnitude: 5.0
Conclusion
So the next time you create a list, remember its real identity. It's a vector — an arrow with a specific magnitude and direction. It’s the fundamental building block that allows us to represent complex, real-world data in a way that a machine can finally understand.
Your Turn...
Did thinking of lists as arrows change your perspective? What's another real-world example that could be a vector? Share your thoughts in the comments below!
This post is a companion to our video on the same topic. The concepts discussed are foundational in Linear Algebra, a key area of mathematics for Machine Learning. For deeper study, resources like NumPy's official documentation are invaluable
Comments
Post a Comment