📚 Introductory Econometrics with MORISTAT

A Practical Guide to Empirical Analysis

Naguib Lallmahomed · naglal@linux-mauritius.com · 2026-06-14


Chapter 11: Machine Learning for Econometrics

🎯 Learning Objectives

Upon completing this chapter, you will be able to:

11.1 What is Machine Learning?

Machine learning (ML) is a branch of artificial intelligence that enables computers to learn from data without being explicitly programmed.

Key Insight: While econometrics focuses on causal inference and hypothesis testing, machine learning focuses on prediction and pattern recognition.

11.1.1 Econometrics vs Machine Learning

AspectEconometricsMachine Learning
GoalCausal inference, hypothesis testingPrediction, pattern recognition
InterpretabilityHigh (coefficients, p-values)Low to moderate (black box)
Model SizeSmall (few variables)Large (many variables)
Data RequirementsModerateLarge
OverfittingControlled via theoryControlled via regularization

11.1.2 Supervised vs Unsupervised Learning

11.2 Regularization: Ridge, Lasso, and Elastic Net

Regularization adds a penalty term to the OLS objective function to prevent overfitting.

11.2.1 Ridge Regression (L2 Penalty)

min Σ(Yᵢ − β₀ − β₁X₁ᵢ − ⋯ − βₖXₖᵢ)² + λΣβⱼ²

11.2.2 Lasso Regression (L1 Penalty)

min Σ(Yᵢ − β₀ − β₁X₁ᵢ − ⋯ − βₖXₖᵢ)² + λΣ|βⱼ|

11.2.3 Elastic Net (L1 + L2 Penalty)

min Σ(Yᵢ − β₀ − β₁X₁ᵢ − ⋯ − βₖXₖᵢ)² + λ₁Σ|βⱼ| + λ₂Σβⱼ²

11.3 Cross-Validation

Cross-validation (CV) is a technique for evaluating model performance on unseen data.

11.3.1 k-Fold Cross-Validation

Example: 5-Fold CV

11.4 Decision Trees and Random Forests

11.4.1 Decision Trees

11.4.2 Random Forests

Key Insight: Random forests often outperform single decision trees and are widely used in applied economics and finance.

11.5 Model Evaluation Metrics

11.5.1 Regression Metrics

MetricFormulaInterpretation
MSEΣ(Yᵢ − Ŷᵢ)² / nAverage squared error (penalizes large errors)
RMSE√MSERoot MSE (in same units as Y)
MAEΣ|Yᵢ − Ŷᵢ| / nAverage absolute error (robust to outliers)
1 − SSE/SSTProportion of variance explained

11.5.2 Classification Metrics

11.6 The Bias-Variance Tradeoff

Key Concept: There is a tradeoff between bias and variance in predictive models.

Total Error = Bias² + Variance + Irreducible Error

11.7 MORISTAT Examples

11.7.1 Preparing Data for ML

MORISTAT> LOAD ml_data.csv
MORISTAT> LIST
MORISTAT> SUMMARY
MORISTAT> CORR

11.7.2 Ridge Regression

MORISTAT> REGRESS Y ~ X1 X2 X3 X4 X5
MORISTAT> DIAG ALL

11.8 Practical Exercises

Exercise 11.1: Econometrics vs ML

You are asked to analyse the effect of education on wages. You have data on 10,000 individuals.

  1. If you want to measure the causal effect of education on wages, which approach (econometrics or ML) is more appropriate?
  2. If you want to predict wages for job applicants, which approach is more appropriate?
  3. Explain why the goals are different.

Solution:

  • Causal inference: Econometrics (control for confounders, instrumental variables)
  • Prediction: Machine Learning (many features, non-linear relationships)
  • The goals differ: econometrics asks why (causality), ML asks what (prediction)

Exercise 11.2: Understanding Regularization

You have a dataset with 100 observations and 50 variables. OLS has high variance (overfitting).

  1. Which regularization method (Ridge, Lasso, Elastic Net) would you use if you believe only a few variables are important?
  2. Which method would you use if all variables are likely important?
  3. What is the role of λ (lambda) in regularization?

Solution:

  • Lasso if only a few variables are important (performs variable selection).
  • Ridge if all variables are important (shrinks coefficients but doesn't zero them).
  • λ controls the strength of the penalty: larger λ → more shrinkage/regularization.

Exercise 11.3: Cross-Validation

You have 200 observations. You use 5-fold cross-validation.

  1. How many observations are in each training set?
  2. How many observations are in each validation set?
  3. Why do we use cross-validation instead of a single train-test split?

Solution:

  • Training set per fold: 160 (80% of 200)
  • Validation set per fold: 40 (20% of 200)
  • Cross-validation reduces variance and provides a more robust estimate of model performance than a single split.

Exercise 11.4: Bias-Variance Tradeoff

You have three models:

  1. Which model is most likely to underfit?
  2. Which model is most likely to overfit?
  3. Which model would you choose for prediction?

Solution:

  • Underfitting: Model A (high bias, too simple)
  • Overfitting: Model B (high variance, too complex)
  • Best for prediction: Model C (Ridge) often balances bias and variance well.

Exercise 11.5: Evaluating Model Performance

You have two forecasting models with the following errors:

  1. Calculate RMSE for both models.
  2. Calculate MAE for both models.
  3. Which model is better and why?

Solution:

  • Model 1 RMSE: √((4+9+1+4+16)/5) = √6.8 = 2.607
  • Model 2 RMSE: √((1+1+0+1+1)/5) = √0.8 = 0.894
  • Model 1 MAE: (2+3+1+2+4)/5 = 2.4
  • Model 2 MAE: (1+1+0+1+1)/5 = 0.8
  • Model 2 is better (lower RMSE and MAE)

11.9 Key Terms

Machine Learning Supervised Learning Unsupervised Learning Regularization Ridge Regression Lasso Regression Elastic Net Cross-Validation k-Fold CV Decision Tree Random Forest Bias-Variance Tradeoff MSE RMSE MAE Overfitting Underfitting Feature Importance AUC-ROC

11.10 Further Reading

🔄 Ready to connect with MORISTAT?