LINEAR ALGEBRA FOR DATA SCIENCE AND MACHINE LEARNING

Swastik Nayak
7 min readApr 12, 2019

--

Let’s start the story by splitting the two beautiful words LINEAR and ALGEBRA. If I jump to Lyman term linear means anything that is in the form of a line or related to line and algebra means anything that is related to equations. In this article, I am going to tell you about how linear algebra will help you in solving problems in the data science & Machine Learning fields.

Now when I am talking about linear algebra, the most important and fundamental thing that comes into our mind is VECTOR. Now, a vector is nothing but a list of numbers.

Representation of vectors

in the above image, you can see the vectors “a” and “b” containing numbers. vector “a’’ is known as column vector as you can see the order or you can see dimension is 4*1 whereas vector “b” is known as a row vector as its dimension is 1*3.

Now, apart from the vector concepts, there are more things that come across our mind when we think about linear algebra, let’s have a look at it.

Now, in the above images, you can see the only single number (i.e. 11) is scalar and as according to the definition of the vector you can see the row and column vector in the above picture. Now as you can see two more things written as “MATRIX” and “TENSOR”. Matrix is nothing but an array of scalars for a given field with a specified number of rows and columns. In the above image, you can see our matrix contains 3 rows and 3 columns. Now, Tensor you can think it as an n-dimensional matrix, It can be the collection of the numbers of matrices along with multiple numbers of vectors. It is difficult to visualize the tensors. The dimension of a tensor is known as its rank. Yes….GUYS this is the word tensor from which the famous deep learning library “TENSOR-FLOW” is evolved.

BUT WHY SHOULD I LEARN THIS?????????

Yeah…. It is a valid question. If you want to switch to the hottest careers in the world like Data Science, Machine Learning, Deep Learning the fundamental Knowledge of linear algebra is the must. Now, As you see in today’s world DATA has become one of the most important resources and to process DATA with the help of these very beautiful algorithms linear algebra is necessary. Behind the scene of every machine learning algorithm linear algebra plays a very important role, whether you go for various dimensionality reduction technique like Principal Component Analysis(PCA), T-SNE(T-distributed Stochastic Neighbourhood Embedding) or go for classical machine learning algorithms like Support Vector Machine (SVM)or K-Nearest Neighbour(KNN) linear algebra is must. Now, the core part of the neural network also works on the heavy operations of linear algebra.

okay now, these things sound interesting, but how will I start…..???? One might say that we know the concepts of vectors, scalars, tensors but IS THIS ENOUGH????….

GLIMPSE OF LINEAR ALGEBRA

At the very beginning of this article, we get a piece of very basic information about the vector, row vector, column vector, matrix, and tensors but what about its geometrical visualization and how it helps us solving machine learning problems. Well, we have to go and check out various properties of vectors to get a strong understanding. Let’s discuss some of the famous properties of vectors.

1. DOT PRODUCT:

DOT PRODUCT OF 2 Vectors A &B

In the above image, we can see that A and B both are columns vectors and we are calculating the dot products by taking the sum of the products of the component of the two vectors A and B. here as we can see there is no angle between A and B that's why the result is scalar having no directions.BUT how to calculate the dot product when we get an angle between the two vectors. Let’s go to another example.

The dot product between vector U and V

From the above image, It is clear that we are taking the “co-sine” value of the angle between them. Let’s say U have to component(x1,x2) and V(y1,y2), But on the line3 why we have taken the transpose of V. Think about it and write in the comment section below. There is a very beautiful piece of mathematics behind it.

Now let’s jump to another property known as Projection.

2. PROJECTION:

Scalar and Vector Projection

Here we can see a diagram where we can see the formula for the projection of vector b on the vector a. projection is a very useful concept and used by one of the famous dimensionality reduction technique known as PCA(Principal Component Analysis). When data resides in higher dimensions to view it we have to push them in lower dimensions which is one of the most important parts of any dimensionality reduction technique where these things play a very crucial role.

3. LINE, PLANE, HYPERPLANE:

LINE:

STRAIGHT LINE EQUATION IN 2D

Let’s consider a 2d plane where there is a line passing through two points let’s say P and Q. let’s assume that the co-ordinate of P(0,b) and Q(x,y) respectively. When x value is 0, the point you get on the y-axis is known as the y-intercept of the line and vice-versa. from the formula written above we can see how to calculate m(i.e.slope of the line). The general equation of a straight line is y=mx+b. You can come across this equation most frequently in linear regression. This equation is the most fundamental equation to solve any regression problem in machine learning. Now, the line converted into a plane in 3D. Let’s get a glimpse of the plane and its equations.

PLANE:

Image of a Plane

Here In 3-D when we have three axes (x,y,z)the general equation of a plane will be ax+by+cz+d=0. The plane is one of the basic concepts that work behind every classical machine learning algorithm. This is the most fundamental concept that you should know before jumping into any core machine learning algorithm. Now, the interesting part lies here. It is not mandatory that always data should be in 2 or 3 dimensions. there are datasets which have got more than 100 or even thousands dimensions. What to do in such kind of scenarios?? For that, we have got hyperplane.

HYPERPLANE:

Image of a hyperplane

If I describe a hyperplane in one single line then I will say “plane in higher dimension is known as hyperplane”. As we can’t view the dimension that is greater than 3-d here you can see a plane in 3-d and how it is separating the points. Let’s see a comparative image between a hyperplane and line to grasp the formula of the hyperplane.

Image result for hyperplane images with equation
Image of the hyperplane and line

Hyperplanes which are passing through origins are represented as the above formula{wt*x(note: t is superscript to W)} where w and x are column vectors. We have to add the intercept terms for the planes which are not passing through the origin. The hyperplane is the core concept of the SVM(Support Vector Machine) which is one of the famous machine learning algorithms. The hyperplane is denoted as the symbol( ∏n)(NOTE: the ’n’ is subscript to the ∏).

Apart from the concepts of this, you can refer to any 12th standard mathematics book to get a more detailed and mathematical overview of the concepts of circle, cuboid, sphere, Hypersphere, ellipse. All these things play an important part in processing machine learning algorithm. From my personal experience what I will suggest you go through the concepts of vector and hyperplane because in most of the machine learning task data-set is always represents as vectors, that's why we all need to grasp the concept of vector and also hyperplane to know how the decision surface is being constructed by various machine learning algorithm.

That’s all from this blog people. Hope that you like the blog, please comment if you retrieve some valuable information from this blog.

HAPPY LEARNING…

--

--

Swastik Nayak

The Datasaurus Associate AI Engineer @AUTOMATEDRETURNS 🤖🤖