Data Foundations
The Python AI Stack — What Each Library Is For
The Python AI Stack — What Each Library Is For
"AI in Python" can feel like a wall of library names. In practice, the stack has a few clear layers, and knowing which layer a problem lives in tells you which tool to reach for — and, for a QA engineer, which kind of testing it needs.
The Layers
| Layer | Libraries | What it's for |
|---|---|---|
| Numerical core | NumPy | Fast arrays and vector maths — everything else builds on it |
| Data wrangling | pandas (or Polars) | Loading, cleaning, joining, summarising tabular data |
| Visualisation | matplotlib, seaborn, plotly | Seeing distributions, trends, outliers |
| Classic ML | scikit-learn | Classification, regression, clustering on tabular data |
| Deep learning | PyTorch (also JAX, TensorFlow) | Training neural networks; mostly specialists |
| Pretrained models | Hugging Face transformers, sentence-transformers | Downloading and running existing models locally |
| LLM APIs | anthropic, other provider SDKs | Calling hosted large language models |
| Validation | Pydantic | Enforcing structure on model inputs and outputs |
| Retrieval | Vector stores: Chroma, pgvector, FAISS | Searching by meaning for RAG |
| Evaluation | pytest + your own eval harness, specialist eval tools | Measuring whether any of it works |
You won't use all of them. This path focuses on the ones most engineers actually touch: NumPy, pandas, scikit-learn, an LLM SDK, embeddings, and — most importantly for QA — evaluation.
Two Very Different Kinds of "AI"
Classic machine learning (Module 2) learns patterns from your labelled data: predict whether a test is flaky from its history, classify a bug's severity from its fields. You train the model, and you own its data.
Large language models (Modules 3–5) are huge pretrained models you call through an API. You don't train them; you instruct them with prompts, give them context (RAG), and let them call tools (agents).
Both share one property that matters enormously for testing: their output is probabilistic. The same input can produce different outputs, and "correct" is often a matter of degree. That's why the final module is about evaluation — and why QA engineers who understand AI systems are in demand.
Setting Up
Create a fresh project with its own environment (see the Master Python path, Lesson 1):
uv init ai-lab && cd ai-lab
uv add numpy pandas matplotlib scikit-learn jupyter
uv add anthropic pydantic sentence-transformers chromadb
Jupyter notebooks (uv run jupyter lab) are great for exploring data step by step. Once something works, move it into normal .py modules with tests — notebooks are for exploration, not for code other people depend on.
Keep API Keys Out of Code
LLM APIs need a key. Store it in an environment variable, never in a notebook or a committed file:
export ANTHROPIC_API_KEY="sk-ant-..." # or use a .env file listed in .gitignore
SDKs read the variable automatically. A key pasted into a notebook cell ends up in git history, screenshots and shared files — and keys are billed per use.
Cost and Data Awareness
Two habits from day one:
- Every LLM call costs money. Use small inputs while developing, cache results, and know roughly what a run costs before you loop over 10,000 rows.
- Know what data you're sending. Production logs and bug reports can contain customer data. Check your company's policy before sending anything to an external API, and strip personal data when you can.
How This Path Is Structured
- Data Foundations — NumPy and pandas on realistic QA data.
- Classic ML — the scikit-learn workflow and, crucially, how to measure it.
- LLM APIs — prompts, structured output, cost, and a working classifier.
- RAG — embeddings, search, and measuring retrieval.
- Tools and Agents — letting models call your functions, safely.
- Testing AI Code — evals, golden datasets, and a capstone.
💬 Discussion
Which repetitive judgement call in your QA work — triage, classification, summarising — would you most like an AI system to help with, and how would you know if it was doing a good job?
Which library is the right first choice for loading, filtering and summarising a CSV of test results?
Next Lesson
NumPy — Arrays, Vectors, and Why Loops Are Slow