← Back to list

The Hidden Mathematics Behind Every AI Model You Use

Have you ever imagined how a subject that is often hated by children during their school years — considered boring and even feared — has…

Sandip Thakuri · 2026-05-04 12:56 · 0 claps · 6.0 min read
#data-science #dimensionality-reduction #mathmatics #linear-algebra #artificial-intelligence
Open on Medium ↗
Wiki topics: ML · Machine Learning AI · AI · General 📐 · Mathematics 🔬 · Science · General 👨‍👩‍👧 · Family & Parenting

The Hidden Mathematics Behind Every AI Model You Use

Have you ever imagined how a subject that is often hated by children during their school years — considered boring and even feared — has become one of the most powerful tools behind the development of Artificial Intelligence? A subject that many students find intimidating, even a nightmare, is actually the foundation of large language models and other AI systems.

Behind all this intelligence lies strong mathematical algorithms and functions. Machines do not think or possess true intelligence; instead, they operate based on logic and computation.

While we see text, images, and videos in a meaningful way, computers and AI perceive them very differently. For example, an image is seen as a matrix of pixel values. Sentences and text are represented as numerical embeddings. A dataset, to a computer, is essentially a massive table of numbers.

A visual Representation of how AI sees the data like image , text

A visual Representation of how AI sees the data like image , text

Today, we will explore some of the key mathematical concepts and their applications in machine learning.

Linear Algebra :

The linear Algebra is the main mathematical foundations that is used in the AI and ML. It provides the tools to represent data, transform it, and extract meaningful structure.Let us explore its core concepts and how each one shows up in real AI applications.

Matrix : A rectangular array of scalars withrows and columns.

Applications in AI/ML: A grayscale image is a matrix of pixel intensities (height × width). A whole dataset is often stored as a matrix where rows = samples and columns = features. . Convolutional kernels are small matrices slid over an image to detec edges and patterns.

Vectors :

A vector is an ordered list of scalar having both point nad the direction. Every data point you feed to a model is a vector: a row in your spreadsheet with age, salary, and purchases becomes a vector. In natural language processing, words are turned into dense vectors (word embeddings) such that “king” — “man” + “woman” ≈ “queen”. A neural network’s hidden layer output is also a vector — the internal representation the network learns.

4. Dot Product (Inner Product)

Definition:

Example: [1,2,3] · [4,5,6] = 4+10+18 = 32

The dot product is the workhorse of linear models. A linear regression prediction is simply y = w · x + b is a dot product plus bias.

Cosine similarity, used to find similar documents or images, is a normalised dot product

Eigenvalues and Eigenvectors

For a square matrix A, an eigenvector v is a special direction that is only stretched (not rotated) when multiplied by A. The stretch factor is called the eigenvalue λ.

A v = λ v, where v ≠ 0 is the eigenvector and λ is the eigenvalue

Eigenvectors reveal the principal “axes” of data — the directions of maximum variance. This is the mathematical heart of PCA, spectral clustering, and Google’s original PageRank algorithm.

Applications in AI/ML: Eigenvectors reveal the “axes” of maximum variance in data. Principal Component Analysis (PCA) sets the eigenvectors of the covariance matrix as the new coordinate axes, projecting data onto the top‑k eigenvectors to reduce dimensions. In graph‑based learning (e.g., spectral clustering), eigenvectors of the graph Laplacian are used to partition nodes. Google’s original PageRank algorithm is an eigenvector problem.

Covariance Matrix

The covariance matrix Σ captures how features vary together across a dataset. For data matrix X ∈ R^(n×d):

Σ = ½(n-1) (X — μ)ᵀ (X — μ)

The (j,k) entry of Σ tells us how feature j and feature k co-vary. Its eigenvectors are exactly the principal components used in PCA.

Applications in AI/ML: The covariance matrix captures how features vary together. Its eigenvectors are the principal components (PCA). In Mahalanobis distance, we use the inverse covariance to measure distance while accounting for feature correlations. Gaussian Mixture Models (GMMs) use covariance matrices to describe the shape and orientation of each cluster. In finance AI, covariance drives portfolio risk models.

The Curse of the dimension ? We might think when there are more data points there will be greater accuracy in the machine learnings. Or we may think like the more information there would be more better predictions. But in the higher dimensions the things work differently.

The curse of dimensionality is the collection of phenomena that make high-dimensional spaces behave in ways that violate every instinct you’ve built from living in 3D.

For example : Consider a unit hypercube [0,1]^d. The fraction of volume in a sub-cube of side 0.1 is (0.1)^d. At d=100, this is 10^−100 — essentially zero. Almost all data points cluster near the boundary, making interior regions completely empty.

In high‑dimensional data (e.g., 1000 features per sample), three disasters happen:

  1. Sparsity — data points are isolated; distances become meaningless (curse of dimensionality).
  2. Redundancy — many features are correlated (e.g., pixel brightness and contrast).
  3. Overfitting — models learn noise instead of signal.

(Left) Volume fraction collapses exponentially with dimensions. (Right) Three disasters of high-dimensional data.

(Left) Volume fraction collapses exponentially with dimensions. (Right) Three disasters of high-dimensional data.

Principle Component Analysis :

PCA solve the problem of Sparsity, Redundancy and overfitting by finding new axes (principal components) that capture the maximum variance in the data, then projecting the data onto only the top few axes. This reduces dimensions while preserving as much information as possible.

The result: a dense, low-dimensional representation where distances are meaningful again, and machine learning algorithms work efficiently without overfitting.

Mathematical Steps :

Given a data matrix X ∈ R^(n×d) (n samples, d original features):

  1. Center the data — subtract the column mean μ from each feature:

X_centered = X − μ

  1. Compute the covariance matrix of the centered data:

Σ = ½(n-1) X_centeredᵀ X_centered (size d×d)

  1. Find eigenvalues and eigenvectors of Σ, sorted in descending order:

Σ vᵢ = λᵢ vᵢ, λ₁ ≥ λ₂ ≥ … ≥ λ_d

  1. Select the top-k eigenvectors to form the projection matrix W (size d×k):

W = [v₁ v₂ … v_k]

  1. Project the centered data into the new k-dimensional space:

Y = X_centered · W (size n×k)

The fraction of variance retained by the top k components is:

PCA in action — from raw 2D data, through finding principal components, to 1D projection retaining maximum variance

PCA in action — from raw 2D data, through finding principal components, to 1D projection retaining maximum variance

Working of the PCA :

PCA attacks the curse of dimensionality by discarding the dimensions where variance is negligible. In practice, for a dataset with hundreds of features (e.g., gene expression or text word counts), often 95% of the variance is captured by only 10–50 principal components. By projecting data onto these few components, PCA transforms a sparse, empty high‑dimensional space into a dense, low‑dimensional representation where distances become meaningful again. This allows algorithms like k‑nearest neighbours, clustering, and even neural networks to work efficiently without overfitting. For example, in face recognition (eigenfaces), each face image of 10,000 pixels is reduced to ≈ 100 principal components, making recognition both fast and robust. In finance, PCA reduces correlated stock movements into a handful of “market factors”. In neuroscience, it finds low‑dimensional neural firing patterns from hundreds of electrodes. Thus, PCA doesn’t just simplify data — it reveals the true, low‑dimensional structure hidden within high‑dimensional noise.

Lets move into the feature Engineering :

Feature Engineering — the art and science of turning raw data into features that a machine learning model can digest effectively. Good feature engineering often matters more than the choice of algorithm.

1. Feature

Definition: A measurable property or characteristic of a phenomenon being observed. . Mathematically, a feature is a scalar value x_j representing the j-th attribute of a data sample. A dataset with n samples and d features is the matrix X ∈ R^(n×d).

For a house price prediction model: x₁ = area (120 m²), x₂ = bedrooms (3), x₃ = age (10 years). The house is the vector [120, 3, 10].

Why it matters ?

A feature is the atomic unit of prediction. In a spam detector, features might include the count of exclamation marks, presence of the word “free”, and the sender’s domain. The model learns a mapping f(x) → y from these features to a label.

Without well-defined features, even the deepest neural network cannot learn effectively. Raw text, images, and audio must be transformed into numerical feature vectors — this transformation process is the essence of feature engineering


메타데이터
post_id
8c981c7d9770
slug
the-hidden-mathematics-behind-every-ai-model-you-use-8c981c7d9770
url
https://medium.com/@sandip122/the-hidden-mathematics-behind-every-ai-model-you-use-8c981c7d9770
canonical_url
https://medium.com/@sandip122/the-hidden-mathematics-behind-every-ai-model-you-use-8c981c7d9770
author_url
https://medium.com/@sandip122
status
ok
fetched_at
2026-06-09 15:37:30