Week 5 Master Guide
Week 5: Linear Algebra, Data Science & Classical Machine Learning
Week 5 Daily Breakdown (7 Days)
Day 1
Day 1: Linear Algebra for AI Engineers — Vectors, Matrices, Norms, Attention & LoRA
1 code file(s) • 2 Q&ADay 2
Week 5 — Day 2: Data Wrangling (`Pandas`), Stratified Splits & Preventing Data Leakage
1 code file(s) • 2 Q&ADay 3
Week 5 — Day 3: Supervised ML — Logistic Regression, Sigmoid & Gradient Descent Coded From Scratch
1 code file(s) • 2 Q&ADay 4
Week 5 — Day 4: Text Vectorization (`TF-IDF`) & Sub-Millisecond Classical Text Classifiers
1 code file(s) • 1 Q&ADay 5
Week 5 — Day 5: Unsupervised Machine Learning — `K-Means` Clustering on Text Embeddings
1 code file(s) • 2 Q&ADay 6
Week 5 — Day 6: ML Evaluation Metrics Deep Dive — Confusion Matrix, Precision, Recall, F1 & ROC-AUC
1 code file(s) • 1 Q&ADay 7
Week 5 — Day 7: Mini-Project (Hybrid Classical ML -> LLM Confidence Cascade Router) + Week 5 Interview
1 code file(s) • 0 Q&AWeek 5: Linear Algebra, Data Science & Classical Machine Learning (week5.md)
Mentor's Note (10+ YOE Staff AI Engineer POV): Why does a Senior AI Engineer still master Linear Algebra (Vectors, Matrices, Cosine Similarity), Data Wrangling, Classical ML (
TF-IDF, Logistic Regression, Decision Trees, Gradient Boosting), Clustering (K-Means), and Precision / Recall / F1 / ROC-AUC in the era of LLMs?
- Embeddings & Vector Databases ARE Linear Algebra (Day 1): Every OpenAI/Gemini embedding is just a 768- or 1536-dimensional vector . Ranking RAG chunks is literally a Matrix-Vector Dot Product ()!
- When NOT to Use an LLM (Days 3 & 4): Calling GPT-4o or Gemini takes
300ms–1,500msand costs money on every call. If you need to route 10,000 incoming server logs per second intoCRITICALvsINFO, a TF-IDF + Logistic Regression / XGBoost classifier runs in0.05 milliseconds(10,000x faster) at$0.00cost!- Evaluating AI Systems (Day 6): Whether you are evaluating a fraud model, a RAG reranker, or an LLM-as-a-Judge guardrail, interviewers will grill you on Precision vs Recall trade-offs, F1-Score, ROC-AUC vs PR-AUC on imbalanced datasets, and Data Leakage!
Week 5 Architecture & Daily Folder Map
text
week05_math_data_science_and_classical_ml/
├── week5.md # Master Week 5 Syllabus & Architecture
├── day01_linear_algebra_vectors_matrices_cosine/ # Day 1: Vectors, Dot Products, L2 Norm & Cosine Math
│ ├── README.md
│ ├── src/linear_algebra_engine.py
│ ├── tests/test_linear_algebra_engine.py
│ └── interview_questions.md
├── day02_data_wrangling_cleaning_and_leakage_splits/ # Day 2: Data Cleaning, Stratified Splits & Leakage
│ ├── README.md
│ ├── src/dataset_pipeline.py
│ ├── tests/test_dataset_pipeline.py
│ └── interview_questions.md
├── day03_supervised_ml_logistic_regression_gradient_descent/# Day 3: Logistic Regression & Gradient Descent Math
│ ├── README.md
│ ├── src/logistic_regression_scratch.py
│ ├── tests/test_logistic_regression_scratch.py
│ └── interview_questions.md
├── day04_tfidf_vectorization_and_fast_text_classifiers/ # Day 4: TF-IDF Math & Sub-Millisecond Alert Classifier
│ ├── README.md
│ ├── src/tfidf_classifier.py
│ ├── tests/test_tfidf_classifier.py
│ └── interview_questions.md
├── day05_unsupervised_ml_kmeans_clustering_embeddings/ # Day 5: K-Means Clustering on Text Embeddings
│ ├── README.md
│ ├── src/kmeans_topic_clusterer.py
│ ├── tests/test_kmeans_topic_clusterer.py
│ └── interview_questions.md
├── day06_ml_evaluation_metrics_precision_recall_f1_auc/ # Day 6: Confusion Matrix, Precision, Recall, F1 & AUC
│ ├── README.md
│ ├── src/metrics_auditor.py
│ ├── tests/test_metrics_auditor.py
│ └── interview_questions.md
└── day07_week5_mini_project_hybrid_ml_llm_router/ # Day 7: Hybrid ML + LLM Confidence Cascade Router
├── README.md
├── src/hybrid_ml_llm_router.py
├── tests/test_hybrid_ml_llm_router.py
└── interview_questions.md
Daily Schedule & Core Mathematical Foundations
| Day | Topic | Core Equations & Theory | Production Deliverable |
|---|---|---|---|
| Day 1 | Linear Algebra: Vectors, Matrices & Cosine Similarity | Dot product ; Norm ; Cosine Similarity ; Matrix multiplication | linear_algebra_engine.py — Pure-Python + NumPy compatible vector/matrix engine & top-K cosine similarity search |
| Day 2 | Data Wrangling, Deduplication & Preventing Data Leakage | Missing value imputation (-score normalization ), Stratified Train/Val/Test splitting, why fitting a scaler on the full dataset before splitting causes Data Leakage | dataset_pipeline.py — Leak-free StandardScaler (fit on train only!) + stratified splitter |
| Day 3 | Supervised ML: Logistic Regression & Gradient Descent | Sigmoid ; Binary Cross-Entropy (Log Loss) ; Gradient descent update | logistic_regression_scratch.py — Trains a binary classifier via Gradient Descent from first principles |
| Day 4 | Text Classification: TF-IDF Vectorization | ; Smooth Inverse Document Frequency | tfidf_classifier.py — Sub-millisecond SRE incident classifier costing $0.00 |
| Day 5 | Unsupervised ML: K-Means Clustering | Lloyd's algorithm: Step 1 (Assign each point to nearest centroid ), Step 2 (Recompute centroids $\boldsymbol{\mu}_k = \frac{1}{ | C_k |
| Day 6 | ML Evaluation Metrics: Precision, Recall, F1 & ROC-AUC | , , , Accuracy Paradox on 99% imbalanced data, ROC-AUC vs PR-AUC | metrics_auditor.py — Complete classification metrics & threshold optimizer |
| Day 7 | Week 5 Mini-Project: Hybrid ML LLM Cascade Router | Routing high-confidence queries () through fast $0.00 Classical ML (0.1ms) and escalating only ambiguous queries () to the expensive LLM (800ms)! | hybrid_ml_llm_router.py — Cuts LLM API costs by 70%+ while maintaining 99% accuracy! |