Understanding Vectors in Machine Learning in a fun way

Understanding Vectors in Machine Learning in a fun way
Photo by John Mark Arnold / Unsplash

Vectors as you may have known since high school are a mathematical representation of a set of numerical values.

The rest of this article is organized into the following sections:

  • Plot
  • Vectors in machine learning
  • Vectors in real life
  • Types of vectors
  • Vector arithmetic
  • Vector operations

Let's understand it with some real-case scenarios.

Plot

Imagine you are a police officer trying to track down a suspect. You have clues such as the suspect's height, weight, and hair color. But how do you put all of this information together to create a mental picture of the suspect?

One way to do this is to use vectors. A vector is a mathematical object that has both magnitude and direction. In this case, the magnitude of the vector would represent the suspect's height, weight, and hair color. The direction of the vector would represent the suspect's location.

By combining multiple vectors, you can create a more complete picture of the suspect. For example, you could combine the vector for the suspect's height with the vector for the suspect's weight to create a vector for the suspect's body mass index (BMI). This would give you a better understanding of the suspect's physical build.

So a vector of such data will look like

[169, 80, 22]

which represents the suspect's height in cms, weight in kg, and BMI respectively.

Vectors in Machine Learning

Vectors are used in machine learning in a similar way. They are used to represent data points, such as images, text, and sounds. By combining multiple vectors, machine learning models can learn to recognize patterns and make predictions.

For example, a machine learning model could be trained to recognize faces by combining vectors that represent the features of a face, such as the eyes, nose, and mouth. The model would learn to identify the patterns that are common to all faces, and then use these patterns to identify new faces.

Vectors are also used in machine learning algorithms. For example, the support vector machine (SVM) algorithm uses vectors to find the best hyperplane that separates two classes of data. The hyperplane is a line or plane that divides the data into two regions, such as the region of positive examples and the region of negative examples. Other ways include:

Feature vectors: Feature vectors are used to represent the features of data. For example, in a classification problem, a feature vector might represent the features of an image, such as the color, brightness, and texture of the image.

Weight vectors: Weight vectors are used to represent the weights of a machine learning model.

Vectors in Real Life

Vectors are used in many different areas of machine learning, including:

  • Natural language processing: Vectors can be used to represent words, sentences, and even entire documents. This can be used for text classification, sentiment analysis, and machine translation tasks.
  • Computer vision: Vectors can be used to represent images, videos, and even 3D objects. This can be used for tasks such as object detection, facial recognition, and image segmentation.
  • Recommendation systems: Vectors can be used to represent users and items. This can be used to recommend products, movies, and other items to users.
  • Robotics: Vectors can be used to represent the position, orientation, and velocity of robots. This can be used for tasks such as navigation, obstacle avoidance, and object manipulation.

A vector could be used to represent the following:

  • The features of a customer, such as their age, income, and location.
  • The pixels of an image.
  • The words in a document.

Types of Vectors

There are many different types of vectors, but some of the most common ones include:

  • Scalar vectors: A scalar vector has a single dimension, and its magnitude is a single number.
  • Vector vectors: A vector vector has two dimensions, and its magnitude is a pair of numbers.
  • Tensor vectors: A tensor vector has three or more dimensions, and its magnitude is a set of numbers.

Vector Arithmetic

Vectors can be added, subtracted, multiplied, and divided. The rules for vector arithmetic are similar to the rules for arithmetic with numbers.

There are many different operations that can be performed on vectors. Some of the most common operations include:

  • Addition: This operation adds two vectors together.
  • Subtraction: This operation subtracts two vectors from each other.
  • Multiplication: This operation multiplies a vector by a scalar.
  • Dot product: This operation takes the dot product of two vectors. The dot product is a measure of the similarity between two vectors.
  • Cross product: This operation takes the cross product of two vectors. The cross product is a vector that is perpendicular to both of the original vectors.

Vector Operations

There are many different vector operations that can be used in machine learning. Some of the most common ones include:

  • Inner product: The inner product of two vectors is the sum of the products of the corresponding components of the vectors. The inner product can be used to measure the similarity between two vectors.
  • Euclidean distance: The Euclidean distance between two vectors is the length of the line segment that connects the two vectors. The Euclidean distance can be used to measure the dissimilarity between two vectors.
  • Cosine similarity: The cosine similarity between two vectors is the cosine of the angle between the vectors. The cosine similarity can be used to measure the similarity between two vectors that have the same direction.

I hope this article has given you a better understanding of vectors and their use in machine learning.