ModelRefs / AI & ML Code Examples

AI & ML Code Examples

Hands-on AI and machine learning examples across Python and modern frameworks.

Overview

Worked Python examples for AI and machine learning: 8 tutorials carrying 13 code blocks, ordered from first syntax to a deployed agent.

Each example opens the tutorial that explains it, where the code sits in an editor you can change and run in the browser.

Worked examples, beginner to advanced

  • Python Basics for AI (beginner, 3 code blocks)

    A hands-on tour of the Python language features every AI engineer needs: variables, data types, control flow, functions, and the I/O primitives used by every model SDK. Pairs with in-browser Pyodide examples so you can run each snippet without leaving the page. The syntax every later example assumes, with runnable snippets.

  • NumPy Fundamentals (beginner, 2 code blocks)

    Vectors, matrices and broadcasting form the math substrate of every ML model. This canonical tutorial covers NumPy arrays, slicing, broadcasting and the linear-algebra primitives used downstream in transformers and embeddings. Arrays and vectorised maths, the layer underneath every ML library.

  • Pandas Data Analysis (beginner, 1 code block)

    Pandas is the universal data manipulation library for ML pipelines. Covers DataFrames, groupby, merge, reshape, and the preprocessing patterns used before every model fit. Loading, filtering and grouping real tabular data.

  • Data Preprocessing (intermediate, 1 code block)

    Data preprocessing converts raw data into model-ready tensors. Covers missing value imputation, outlier handling, normalisation, train/val/test splits, and sklearn Pipeline. Cleaning and preparing data before a model ever sees it.

  • Linear Regression (intermediate, 3 code blocks)

    Linear regression is the simplest supervised model and a perfect harness for learning the train/eval/deploy loop. This canonical tutorial walks through fitting, evaluating with MSE, and shipping a tiny prediction service. A full worked model in scikit-learn, fit through to evaluation.

  • Classification (intermediate, 1 code block)

    Classification covers the workhorse production task of mapping inputs to discrete labels. This canonical tutorial covers logistic regression, evaluation metrics (precision/recall/F1), and class-imbalance traps that bite in production. Predicting a category, and reading the metrics that judge it.

  • Build a Production RAG Stack (advanced, 1 code block)

    A reference walkthrough for assembling a production Retrieval-Augmented Generation stack: chunking strategy, embedding choice, vector store, retrieval evaluation, prompt template, grounded answer generation and observability. Retrieval, chunking and generation assembled into one pipeline.

  • Ship an Agentic System (advanced, 1 code block)

    A reference build of a production agentic system: tool schemas, planner choice, memory, circuit breakers, retries and the observability you need to trust an autonomous loop with real customer actions. A tool-using agent taken from loop to deployable service.

Continue your research

Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to AI & ML Code Examples.