Master the mathematical foundations for Machine Learning and AI
1. Vector Representation
A vector is an ordered list of numbers representing magnitude and direction in n-dimensional space.
Current Vectors:
vโ = [3, 2]
vโ = [1, 4]
2. Dot Product (Inner Product)
Measures how much two vectors point in the same direction. Result is a scalar (single number).
Calculation:
vโ ยท vโ = (3)(1) + (2)(4) = 11.00
3. Vector Magnitude (Length)
The length or size of a vector, calculated using the Pythagorean theorem.
Calculations:
||vโ|| = โ(3ยฒ + 2ยฒ) = 3.61
||vโ|| = โ(1ยฒ + 4ยฒ) = 4.12
4. Cosine Similarity
Measures the angle between vectors. Range: [-1, 1]. Value of 1 means same direction, -1 means opposite, 0 means perpendicular.
Result:
cos(ฮธ) = 11.00 / (3.61 ร 4.12) = 0.740
Angle ฮธ = 42.3ยฐ
5. Unit Vector (Normalization)
A vector with magnitude 1, pointing in the same direction as the original. Used for direction-only comparisons.
6. Vector Addition & Scalar Multiplication
Addition combines vectors element-wise. Scalar multiplication scales the vector's magnitude.
K-Nearest Neighbors (KNN)
Uses vector magnitude to calculate Euclidean distance:
Finds k closest data points to classify new samples
Support Vector Machines (SVM)
Decision boundary: (dot product)
Maximizes margin between classes using vector operations
Neural Networks
Layer computation: (matrix-vector multiplication)
Weights are vectors, activations are vectors
Cosine Similarity (Text/Recommendation)
Document similarity:
Used in recommendation systems and NLP
Principal Component Analysis (PCA)
Finds principal components (eigenvectors) using vector projections
Dimensionality reduction through vector transformations
Gradient Descent
Update rule:
Gradient is a vector pointing in direction of steepest ascent
Adjust the vectors to see how dot product, magnitude, and angle change in real-time.
Dot Product (vโ ยท vโ): 11.00
Magnitude ||vโ||: 3.61
Magnitude ||vโ||: 4.12
Cosine Similarity: 0.740
Angle between vectors: 42.3ยฐ
Yellow arc shows the angle (42.3ยฐ) between vectors
Used in neural networks for layer transformations, linear regression for predictions, and image transformations.