Within the empire of mathematics, there are the concepts that lay the foundation for appreciation of directions, magnitudes, and all the diverse relationships between them. This engaging notion involves simply vectors. For instance, try to visualize yourself amid the thought that you are at a crossroads in life and must pick the right direction. The beckoning of every path is a special beauty that will take you to a place you had not imagined before. It is already yours, eagerly waiting for you at the endpoint. They are considered vectors in mathematics, which are quantities that show direction and magnitude.
Let me view this notion more closely. Imagine a vector in space starting from a given point to another. Here, what the vector represents, in essence, can be seen with the help of an arrow. The size of that line can be read to indicate the amount (or the distance) covered, as well as its direction—the directional signs that lead the way for calculus.
Today, vectors outlived the ordinary world and veered into mathematically abstract territories. They can be represented mathematically as sequences of numbers that simultaneously reduce their numerical and directional values to manageable alternatives. Vectors play a crucial role in mathematical components that permit many theories, such as describing a point in space or the force applied to an object. Similarly, the speed of a car is another example of a vector.
Vectors in Linear Transformations
A group of vectors is often presented in a matrix format, where the row is the point of data and the column is the feature(s). Matrices enable the platform of an array of large sets of data into storage. Such operations as addition, multiplication, and transposition can be performed. Linear transformations refer to the cases in which the data points are transferred from one space to another, keeping the relationships of the data points. Transformation processes are aligned to the multiplication of input vectors and weight matrices using activation functions. Dense layers in neural networks and convolution layers in CNNs are also represented as linear transformations. Let’s dive into a commonly used linear transformation function in machine learning: standardization, which also goes by z-score normalization.
$$X_{standardized} = \frac{X – \mu}{\sigma}$$
Where X is the column of the matrix, μ is an average of that feature, and σ is a standard deviation of that feature.
Vectors in Machine Learning
In this scenario, vectors act as keypoints where data points, model parameters, and gradients are portrayed.
Data Representation: In ML, the datasets are formed as a set of matrices in which each row shows an individual data point. On the other hand, a column describes features. These can be defined by numerics, categorical features, or embedded. Vectors are the same as the individual data points used to fill these matrices. An example of this could be the representation of each image in the image classification task as a vector of pixel values. Let’s examine real-life data representation by the vector approach with a classification task example.
A sample dataset of animals has two features: height in centimeters and weight in kg. Our goal is to categorize animals into two groups, which are tigers and elephants, based on their height and weight.
Animal | Height (cm) | Weight (kg) |
---|---|---|
Tiger | 105 | 210 |
Elephant | 350 | 2000 |
Tiger | 120 | 300 |
Elephant | 370 | 2500 |
In this example, each row of the dataset is considered a vector. Every vector is one animal, and it is also represents height and weight. A first vector representing the first animal, the tiger, is : [105, 210] and second vector, the elephant, is [350, 2000] goes on and so does.
What you see below is a vector matrix that was derived from our dataset. Each row in this matrix represents an animal, and each column corresponds to a feature, e.g., height, weight.
\[\begin{bmatrix}
105 & 210 \\
350 & 2000 \\
120 & 300 \\
370 & 2500
\end{bmatrix}\]
Thanks to this vector representation, we can use our dataset as an input of different ML algorithms to do tasks such as classification. In other words, we could teach our learning tools (logistic regression or neural networks) how the examples of features (height and weight) correlate with animal categories (tiger and elephant) to let us classify new animals based on their height and weight.
import numpy as np
from sklearn.preprocessing import StandardScaler
# Define the animal dataset
data = np.array([
[105, 210], # Tiger
[350, 2000], # Elephant
[120, 300], # Tiger
[370, 2500] # Elephant
])
# Apply Standard Scaler function on Animal dataset
scaler = StandardScaler()
scaler.fit(data)
scaled_data = scaler.transform(data)
# Formatted to 4 decimal places
scaled_data_formatted = np.around(scaled_data, decimals=4)
# Print Result
print("Animal Dataset (Original):")
print(data)
print("\nAnimal Dataset (Scaled):")
print(scaled_data_formatted)