So ... What Actually is a Matrix ? : Data Science Basics

ritvikmath · Beginner ·📐 ML Fundamentals ·6y ago

Key Takeaways

The video explains the concept of matrices in data science, covering their definition, uses, and properties from both computer science and math perspectives, including linear transformations and matrix vector multiplication. It highlights how matrices are used for data storage and can be indexed, and how they preserve certain coordinates while transforming vectors.

Full Transcript

[Music] hello everybody in this video we're gonna be talking about what actually is a matrix and that might seem like kind of a weird topic to be talking about on this data science channel because matrices are the very first thing we learned in our introductory linear algebra course or even before we might learn them in high school in algebra 2 for example they seem to be the basic building blocks for everything we do afterward so why are we taking a step all the way back to what actually is a matrix well the reason is that in my studies and in my experience I realized that there's kind of two different ways to think about the same object that we call a matrix there's kind of the computer science students perspective of what a matrix is and there's the math students perspective of what a matrix is and neither of them is correct well I mean they're both correct neither of them are necessarily correct I should say it really depends on what application you're using the matrix for and we're going to get into all of that so the first thing we'll talk about is the computer science students perspective so from a computer science students perspective a matrix is just a n by m array of numbers so for example if we were to populate a few of them we could like one here we could put two here we could put five down here let's say this five is at position I so row I and then call them J okay so we would say that if this matrix was called a and we want to index it AI J is equal to five and that's mostly what a matrix is for a computer science students perspective it's a type of data structure that stores numbers or maybe strings or whatever inside of it and we can index it like this what kind of things do computer science students care about with matrices well they care a lot about the speed of various operations on matrices for example if I want to access an element like this in the matrix how long does that take if I want to add one matrix to another matrix how long does that take if I want to delete a certain element for a matrix or if I want to change a certain element of a matrix or if I want to do an operation on every single element of a matrix how long would that take and and they care about these things because usually in computer science if you're using a matrix you're using it to store some set of values and as that set of values grows lengthwise or column wise we care a lot about how bad our performance is going to suffer is it going to go up like exponentially linearly what's the deal so that's kind of the computer science students idea of a matrix and this is a very powerful concept if you plan on using a matrix for data storage changing the data deleting the data things like that so that's where that comes in now we're going to jump over to this side of the board and talk about a math students perspective of a matrix and in this channel we're gonna be using this perspective a lot more just because we're touching on a lot of the foundations of data science and linear algebra so this this perspective is gonna be a little bit more useful for our purposes okay so from a math students perspective a matrix is a type of linear transformation so let me try to elaborate a lot on that a little bit so this matrix is an N by M matrix so this n by M matrix it's job basically is to take a vector that lives in RM and for those of you who need a refresher RM is basically the space of real numbers a vector that has M components in it can you see that there so this got cut off this is a vector that has M different components in it so this matrix its job its role is basically to take any vector that lives in RM that has M different numbers in it and map it to a different vector which lives in a completely different dimensional space which is our n so this has n different components in that vector and can be bigger than M it can be the same it can be smaller it doesn't really matter okay so the job of this matrix is to take a vector in RM and map it to a vector in R and ok and how does it do that well it does it through a basic matrix vector multiplication so if we take a vector and we erase this here if we take a vector like this that lives in our M and we do this multiplication with this matrix a with this vector V we're going to get back a different vector run out of room here so I'll put it right down here we're gonna get a different vector which lives in our end okay so that is what a matrix is I don't wanna make this idea a little bit more concrete so we're gonna go through a couple of examples of how a matrix does this linear transformation in geometric space okay so here are two different matrices we see that this one here is a rectangle it's 2 by 3 and this one here is a square it's 2 by 2 and they both represent linear transformations so as we saw before from the math students perspective of a matrix this matrix here a is going to map a vector that lives in r3 so three dimensional space on to a vector that lives in r2 so two dimensional space so that's the role of that matrix a matrix B on the other hand maps a vector living in two dimensional space to a potentially different vector living in two dimensional space now let's look at geometrically how these transformations actually look to get a feel for what does a linear transformation actually imply the harder one to look at will be a so let's start with a first let's since it's going from three dimensional space to two dimensional space let's try to draw a three dimensional coordinate axis as best I can so and then I'll put one coming like this so here's the x y and the z axis okay now let's take a vector in three dimensional space let's take the vector let's do the X will be two units the Y will be one unit actually let's do Y is three units so it's here and then the Z will be one unit let's say so that vector looks like this it's the vector 2 3 1 what happens when we feed that vector 2 3 1 into our matrix a so what's going to happen is we're going to get 1 0 0 1 0 0 and we're gonna get 2 3 1 if you remember your rules of matrix vector multiplication we basically multiply one by the two so we get 2 + 0 by the 3 we get 0 + 0 by the 1 we get 0 + we knew 0 times 2 is 0 plus 1 times 3 is 3 plus 0 times 1 is 0 so we get the result as 2 comma 3 okay so I'm gonna write that right here so we get the result as 2 comma 3 and how do we see that on this plane so that's basically 2 comma 3 like right there so if it wasn't already clear what this transformation is doing is the best way to imagine it is let's say there's a light source coming from above on the 3 dimensional plane this is saying that if you have any vector in the three dimensional plane and you take a light source from above or maybe electors from below if it's negative then what is the projection of that three-dimensional vector going to be on our two-dimensional XY plane and you can see why that's happening because basically what this transformation is doing its preserving the x coordinate preserving the y coordinate and zeroing out in the z coordinate so the Z coordinate always ends up as 0 in fact it doesn't even really exist anymore and all we're doing is just preserving the x coordinate in the top one and then the y coordinate in the bottom one ok so that's the type of linear transformation this matrix does now let's close the video by looking at the type of linear transformation that's done by this other matrix here B so again let's draw a picture let's say we have our coordinate axes remember here we're working just in two dimensions to two dimensions so let's say our 1 2 3 4 1 2 let's say this is our vector so this is 4 comma 2 what happens to 4 comma 2 when we run it through this linear transformation B remember that's done by executing a matrix vector multiplication so we have 2 0 minus 2 choose negative 2 0 0 minus 2 and we run through 4 & 2 and what do we get back so we're going to get back negative 2 times 4 is a negative 8 this is 0 0 times 4 is 0 negative 2 times 2 is negative 4 so the vector we get back is at minus 8 and negative 4 so let's see 1 2 3 4 1 2 3 4 5 6 7 8 all the way over there so that vector looks like this now what how does that vector compare to that vector well it's double the length right basically this one was for two this one is minus eight minus four so it's double the length and it's pointing in the complete opposite direction so that if you took this and you rotated it 180 degrees that's the direction it points in and you can see why that's the case if you look at matrix B the double the length part is the easier one to see you see that there's two here so it's going to double every single coordinate that gets put into there we see this zero and this is zero here right so that means that it's preserving the x-coordinate in the negative fashion it's preserving the y-coordinate in the negative fashion and it's doubling the magnitude of both of them so that's kind of how that numerical story translates through this geometric story so this whole video was just to say that from a math students perspective and for a data science perspective it's going to be best to kind of think about matrices as linear transformations as objects yes there are collections of numbers but they are collections of numbers that we need to treat as operations taking Val vectors from some space into some other space whether that's a higher dimensional space a lower dimensional space in the same dimensional space it's one of those options okay and of course the computer science perspective of a matrix is going to be very important for other aspects of data science like when we have data frames in the code and we care about how efficiently they're getting manipulated but for the conceptual part it's best to think about matrices as linear transformations mapping vectors from one space to a different space okay so until next time

Original Description

What's the best way to think about a matrix for data science? --- Like, Subscribe, and Hit that Bell to get all the latest videos from ritvikmath ~ --- Check out my Medium: https://medium.com/@ritvikmathematics
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from ritvikmath · ritvikmath · 56 of 60

1 Math Team Update
Math Team Update
ritvikmath
2 Single Variable Calculus Volume of a Sphere - Proof 1
Single Variable Calculus Volume of a Sphere - Proof 1
ritvikmath
3 Single Variable Calculus Volume of a Sphere - Proof 2
Single Variable Calculus Volume of a Sphere - Proof 2
ritvikmath
4 Multivariable Calculus Volume of a Sphere Proof - Triple Integrals
Multivariable Calculus Volume of a Sphere Proof - Triple Integrals
ritvikmath
5 Multivariable Calculus Volume of a Sphere Proof - Double Integrals
Multivariable Calculus Volume of a Sphere Proof - Double Integrals
ritvikmath
6 The Euclidian Algorithm
The Euclidian Algorithm
ritvikmath
7 Proving the Chain Rule
Proving the Chain Rule
ritvikmath
8 Proving the Fundamental Theorem of Calculus Part 1
Proving the Fundamental Theorem of Calculus Part 1
ritvikmath
9 Proving the Fundamental Theorem of Calculus Part 2
Proving the Fundamental Theorem of Calculus Part 2
ritvikmath
10 Math Puzzle - Poison Perplexity
Math Puzzle - Poison Perplexity
ritvikmath
11 Math Puzzle - Poison Perplexity - Solution
Math Puzzle - Poison Perplexity - Solution
ritvikmath
12 Expected Value and Variance of Continuous Random Variables (Calculus)
Expected Value and Variance of Continuous Random Variables (Calculus)
ritvikmath
13 Expected Value and Variance of Discrete Random Variables (No Calculus)
Expected Value and Variance of Discrete Random Variables (No Calculus)
ritvikmath
14 Array Method
Array Method
ritvikmath
15 Complex Power Series and their Derivatives
Complex Power Series and their Derivatives
ritvikmath
16 Distributions - Intro
Distributions - Intro
ritvikmath
17 The Poisson Distribution
The Poisson Distribution
ritvikmath
18 The Bernoulli Distribution
The Bernoulli Distribution
ritvikmath
19 The Binomial Distribution
The Binomial Distribution
ritvikmath
20 The Continuous Uniform Distribution
The Continuous Uniform Distribution
ritvikmath
21 The Geometric Distribution
The Geometric Distribution
ritvikmath
22 The Triangular Distribution
The Triangular Distribution
ritvikmath
23 The Exponential Distribution
The Exponential Distribution
ritvikmath
24 The Borel Distribution + Notes on Poisson Distribution
The Borel Distribution + Notes on Poisson Distribution
ritvikmath
25 The Gamma Distribution
The Gamma Distribution
ritvikmath
26 The Normal Distribution
The Normal Distribution
ritvikmath
27 The Laplace Distribution
The Laplace Distribution
ritvikmath
28 The Chi - Squared Distribution
The Chi - Squared Distribution
ritvikmath
29 Overfitting
Overfitting
ritvikmath
30 Vector Norms
Vector Norms
ritvikmath
31 Truths Behind the Titanic : K-Nearest Neighbor
Truths Behind the Titanic : K-Nearest Neighbor
ritvikmath
32 The Mathematics of Breakups
The Mathematics of Breakups
ritvikmath
33 Sillyfish
Sillyfish
ritvikmath
34 Finding Optimal Paths - Dynamic Programming
Finding Optimal Paths - Dynamic Programming
ritvikmath
35 HowToDataScience : Scraping Twitter Data
HowToDataScience : Scraping Twitter Data
ritvikmath
36 Decision Trees
Decision Trees
ritvikmath
37 Perceptron
Perceptron
ritvikmath
38 Naive Bayes
Naive Bayes
ritvikmath
39 K-Nearest Neighbor
K-Nearest Neighbor
ritvikmath
40 Evaluating Machine Learning Models
Evaluating Machine Learning Models
ritvikmath
41 Decision Tree Pruning
Decision Tree Pruning
ritvikmath
42 K-Means Clustering
K-Means Clustering
ritvikmath
43 Gaussian Mixture Model
Gaussian Mixture Model
ritvikmath
44 Data Science - Fuzzy Record Matching
Data Science - Fuzzy Record Matching
ritvikmath
45 Time Series Talk : Autocorrelation and Partial Autocorrelation
Time Series Talk : Autocorrelation and Partial Autocorrelation
ritvikmath
46 Time Series Talk : Autoregressive Model
Time Series Talk : Autoregressive Model
ritvikmath
47 Time Series Talk : Moving Average Model
Time Series Talk : Moving Average Model
ritvikmath
48 Time Series Talk : ARMA Model
Time Series Talk : ARMA Model
ritvikmath
49 Time Series Talk : ARCH Model
Time Series Talk : ARCH Model
ritvikmath
50 Time Series Talk : White Noise
Time Series Talk : White Noise
ritvikmath
51 Time Series Talk : Stationarity
Time Series Talk : Stationarity
ritvikmath
52 Time Series Talk : ARIMA Model
Time Series Talk : ARIMA Model
ritvikmath
53 Time Series Talk : Lag Operator
Time Series Talk : Lag Operator
ritvikmath
54 Time Series Talk : What is Seasonality ?
Time Series Talk : What is Seasonality ?
ritvikmath
55 Time Series Talk : Seasonal ARIMA Model
Time Series Talk : Seasonal ARIMA Model
ritvikmath
So ... What Actually is a Matrix ? : Data Science Basics
So ... What Actually is a Matrix ? : Data Science Basics
ritvikmath
57 Derivative of a Matrix : Data Science Basics
Derivative of a Matrix : Data Science Basics
ritvikmath
58 Basics of PCA (Principal Component Analysis) : Data Science Concepts
Basics of PCA (Principal Component Analysis) : Data Science Concepts
ritvikmath
59 Eigenvalues & Eigenvectors : Data Science Basics
Eigenvalues & Eigenvectors : Data Science Basics
ritvikmath
60 The Covariance Matrix : Data Science Basics
The Covariance Matrix : Data Science Basics
ritvikmath

This video teaches the basics of matrices in data science, covering their definition, properties, and uses in linear transformations and data storage. It explains how matrices can be indexed, added, and used to transform vectors, providing a foundational understanding of matrices in ML fundamentals. By watching this video, viewers will gain a solid grasp of matrix basics and be able to apply linear transformations and perform matrix vector multiplication.

Key Takeaways
  1. Index a matrix like AI J is equal to five
  2. Access an element in a matrix
  3. Add one matrix to another matrix
  4. Delete a certain element from a matrix
  5. Change a certain element of a matrix
  6. Perform matrix vector multiplication to transform a vector
  7. Draw a 3D coordinate axis to visualize the transformation
  8. Project a 3D vector onto a 2D plane to demonstrate the transformation
💡 Matrices are a fundamental concept in data science, used for data storage and linear transformations, and understanding their properties and uses is crucial for working with ML fundamentals.

Related Reads

Up next
Difference between MCP & API | MCP vs API Explained | Why AI Needs MCP | Tamil | Karthik's Show
Karthik's Show
Watch →