Getting a Handle on Vector for Machine Learning

The word vector comes from the Latin for “carrier”, reason might be the nature of vector to move from one location to another. In physics, a Vector is an object that moves around a physical space. In Data Science and Machine Learning we generalize this idea to think vector as a list of attributes of an object. So Vectors are used to represent objects, observations and predictions.

Say we want to represent a house having 2 bedrooms, 1 bathroom, 150-meter square and cost around $ 20,000. Based on the information we know about this house, we can represent the house as a vector:

Based on this vector, our machine learning predicts that there is 45% chance that this house will give me profit if I buy, 5% chance that it will be a bad deal(loss) and 50% chance that the price of house will not change at all. We can represent this prediction in a vector as:

Vectors in Python

There are multiple ways we can define a vector in Python, the simplest on being a list:

Python Lists are very good, but in Machine Learning we have deal with lot of scientific calculations,so it is much convenient to represent a vector in Python as a NumPy array as Numpy array does the thing what we expect when we add, multiply vectors.

Vector Arithmetic

In this section, we will illustrate simple vector-vector arithmetic, where all operations are performed element-wise.

Vector Addition

Two vector of equal length when added produce a new vector of the same length. Each element of the new vector at index i is calculated as the sum of the other element at that particular index i.

Vector Subtraction

Two vectors of equal length can be subtracted to produce a new vector of the same length. Each element of the new vector at index i is calculated as the difference of the other elements at that particular index i.

Vector Multiplication

Two vector of equal length can be multiplied together to create a new vector of same length. Like with addition and subtraction, vector multiplication is done element wise.

Vector Division

Two vector of equal length can be divided element wise to calculate a new vector of same length.

Vector Norms

The term Norm is typically used to represent the length or magnitude of a vector. The norm of vector v is denoted by ||v||.

--

--