Econometrics bridge: PCA, factor analysis, clustering
Estimated time: 90 min
Lab: Open browser lab
Code: Python · R
Why this should feel familiar
Unsupervised learning looks for structure when there is no observed target y. For an econometrician, PCA is already a canonical unsupervised algorithm. Modern representation learning extends this idea with nonlinear encoders and large-scale objectives.
Mathematical core
K-means chooses cluster assignments \(c_i\) and centroids \(\mu_k\) to minimize
\[ \sum_i\|x_i-\mu_{c_i}\|^2. \]PCA chooses a low-dimensional linear subspace maximizing explained variance or minimizing squared reconstruction error.
An autoencoder replaces linear projection with learned nonlinear maps:
\[ z=f_\theta(x),\qquad \hat x=g_\phi(z), \]and minimizes
\[ \sum_i\|x_i-g_\phi(f_\theta(x_i))\|^2. \]The latent z is an estimated representation rather than a directly observed variable.
Plain-English translation
Unsupervised does not mean “no objective.” It means there is no externally supplied label for the main task. The learning signal can come from reconstruction, co-occurrence, contrastive relationships, or other structure in the data.
What changes when we move from econometrics to AI?
The recurring shift is from a small, analyst-specified representation toward a larger learned representation. The underlying statistical questions do not disappear: What is the sample? What is conditioned on? What is estimated? What objective is optimized? Which observations were used to choose hyperparameters? How will uncertainty and distribution shift be handled?
AI terminology becomes much easier when these questions are kept explicit. Whenever you encounter a new architecture, identify four objects: inputs, parameterized transformation, training objective, and evaluation design.
Interactive browser lab
Step through k-means one iteration at a time and see assignment and centroid updates.
Before changing a control, predict the direction of the effect. Then manipulate one control at a time. The goal is not merely to produce a pretty visualization; it is to connect a parameter change to a mathematical statement.
Python and R lab
The Python and R examples implement the same core object as the browser lab. The Python code intentionally favors NumPy and explicit matrix operations. The R code favors base R and explicit loops/matrix algebra. Once the mechanics are clear, the same ideas can be implemented with PyTorch, TensorFlow, JAX, torch for R, or other frameworks.
Check your understanding
- Identify the random variables, observed variables, and estimated parameters in this module.
- State the objective function or equilibrium condition.
- Name the closest concept you already knew from econometrics and one important difference.
- Predict one failure mode caused by poor data, poor optimization, or poor evaluation.
Learner output
Compare PCA/factor-analysis intuition with an autoencoder. What becomes more flexible and what becomes harder to interpret?