Generative AI for Business Analytics

A Hands-On Practitioner’s Guide

Author

Murtaza Nasir

Published

August 2026

Preface

This book is for the analyst who can already write a SQL query, build a dashboard, and load a CSV into pandas, and who now wants to build systems that read documents, answer questions, take actions, and create their own training data. Building such systems is a different occupation from the one most analysts trained for and from the one most software engineers practice, occupying the ground between the two, and it is that intermediate work this book sets out to teach.

Each chapter ties one capability to a concrete business problem, implements it in code you can run, and then measures whether the result worked; across the book, these chapters accumulate into a single working system of the kind an analytics desk at a mid-sized company might actually operate. The remainder of this preface describes who the book is written for, what it assumes you already know, and how to find a path through its chapters.

Who this book is for

This book is written for one reader who arrives by two routes: the working analyst or data scientist who is being asked to put generative AI to work on the messy parts of the business (the document pile, the support queue, the forecast nobody has time to fit by hand), and the graduate student in analytics, business, or applied computing who is heading toward that same desk. In either case you bring, or are building, the knowledge of the data and the stakeholders, and the book supplies the complementary discipline: how to build systems on top of models you did not train and cannot fully predict, along one continuous path that runs from the first request you make of a model to a finished system whose quality you can measure.

A book with this title could promise several different things, so it is best to be precise about which of them this one delivers. If you are after the theory of how these models work, the mathematics of transformers and attention, a theoretical text will serve you better; if you want a management-level overview of AI in business without writing any code, this book asks more of you than that; and if you are an engineer who wants to build full-scale software applications, or who needs depth on training infrastructure and large-scale operations, you will find it pitched a level above the model and a level below the cluster. This book covers the middle layer between those extremes, where the analyst’s work actually happens.

How this book is different

The topic list resembles that of other books on the subject; the difference lies in the execution. The business problems are real ones (reading SEC filings, triaging support tickets, forecasting demand, screening resumes), and the code and its outputs are real as well: every result shown is what the code actually returned when it ran. Three disciplines that other books leave optional run through every chapter here as built-in sections: how to evaluate what you built, what it costs in business terms, and when it crosses into regulated territory.

What you should already know

The prerequisites are modest. You should be comfortable with:

  • Python at a working level. Writing and reading functions, lists and dictionaries, loops and comprehensions, and f-strings, and following a class definition or a decorator when you meet one (we use small classes throughout to describe the structure of data). Expert knowledge is not required: if you can write a script that loads a file, transforms it, and prints a result, you know enough to begin.
  • pandas. Loading a dataframe, selecting columns, filtering rows, grouping and aggregating. Nearly every chapter uses it, and since the explanations in this book are reserved for the generative-AI material, pandas itself is treated as already familiar.
  • A terminal and a code editor. Running a command, installing a package, cloning a repository, opening a notebook. Appendix A builds all of this up from a clean machine step by step, so basic familiarity is sufficient.
  • A little statistics. Averages and percentages, and the idea of holding back a test set to score against. Knowing accuracy, precision and recall, a confusion matrix, or what a classifier and clustering do will help in a few places (Part V most of all), but each idea is reintroduced where it is used.
  • Reading SQL, which is helpful although the book treats it as optional. Chapter 14 turns plain English into SQL and runs it; the ability to read a SELECT with a JOIN is sufficient.

Equally important is what the book does not assume. It requires no linear algebra or calculus, none of the mathematics of transformers or attention, no prior experience with a deep-learning framework (PyTorch appears in the two GPU chapters and is walked through line by line), no background in production operations or cluster management, and, above all, no prior exposure to generative AI. The book’s first program is a few lines that ask a model one question, and the rest of the book builds outward from that starting point.

Generative AI carries its own vocabulary, and you are not expected to bring it with you. Each term is introduced where it first appears and collected in Appendix F, the glossary; when a word is unfamiliar, that is where to look.

What you can do by the end

By the last page you should be able to:

  1. Build a retrieval system over a real business document corpus, evaluate it, and explain why the final version is better than the one you started with.
  2. Build an agentic pipeline that uses tools (search, calculation, lookups, your own internal services), and judge whether an agent or a simpler workflow is the right answer.
  3. Fine-tune a small open-weight model for a domain task and decide whether that fine-tune was worth the cost.
  4. Generate synthetic data, mix it with real data without poisoning your training set, and use it to distill a smaller model.
  5. Evaluate any of the above with metrics that reflect what is at stake for the business, which are rarely the ones a benchmark leaderboard reports.
  6. Reason about cost, latency, safety, and compliance for any of the above in plain business terms.

You will not learn to train a foundation model from scratch or to derive the mathematics of attention, because other books cover those subjects well and this one does not duplicate them.

How this book is organized

The book has ten parts, and a single system runs through all of them: picture yourself on the analytics desk at a mid-sized company, where across these chapters we build one working system that triages the incoming ticket queue, answers questions over the company’s filings and reports, and runs an agent when a question takes more than one step. Parts I through IV grow that spine in order, from the first call to a model to a working retrieval-and-agent system. Parts V through VIII add the capabilities the desk reaches for as the work demands them. Part IX turns the result into something a stakeholder can rely on, and by the last chapter we have wrapped it in a small web service a colleague can actually use.

  • Part I (Chapters 1-4) covers the substrate: calling models, prompts, structured outputs, and where models run.
  • Part II (Chapters 5-7) is the document layer: extracting text, embedding it, and answering questions over it.
  • Part III (Chapters 8-10) improves retrieval and introduces the evaluation toolkit that the rest of the book uses.
  • Part IV (Chapters 11-12) covers workflows and agents.
  • Part V (Chapters 13-14) turns the stack toward classic analytics workloads: clustering and classification over your text via embeddings, and natural-language question answering over your tables via SQL, the highest-ROI business use of these models.
  • Part VI (Chapters 15-17) is model customization (fine-tuning, synthetic data, distillation).
  • Part VII (Chapters 18-20) goes beyond text: speech, vision-language models, time-series forecasting.
  • Part VIII (Chapters 21-22) is structured knowledge: knowledge graphs and Graph RAG.
  • Part IX (Chapters 23-25) is the production discipline that turns a working notebook into something a stakeholder relies on.
  • Part X (the projects) is where you take over: capstone projects with briefs, milestones, and evaluation gates, sized like real work.

Appendices cover setup, benchmarking, cost modeling, compliance, vendor selection, a glossary, further reading, and working alongside AI coding tools.

Three threads that run through every chapter

Evaluation. Every chapter that builds something also evaluates it, because the most common failure in generative AI projects is putting something into use that nobody knew how to measure. Chapter 9 is the toolkit; every later chapter applies it.

Cost. Every applied chapter includes a cost callout that works out the economics of what the chapter built, sometimes as dollars per unit of work (per ticket resolved, per applicant screened, per question answered) and sometimes as the structure of the bill (which design choice drives it, and when an added technique pays for itself), because raw token counts mean little to a business sponsor.

Compliance. Where regulated data is involved (financial filings, customer records, anything that could identify a person or reveal their health information), each chapter points to Appendix D, which covers the EU AI Act, the US state landscape, redaction recipes, and audit-trail patterns. The book teaches enough for you to recognize when you have crossed into a regulated use case, while the decisions that follow remain matters for legal counsel.

How to read it

The default path is the one the figure shows: Parts I through III are the spine and are read in order, with Chapter 9 on evaluation the most important chapter among them, because every later chapter assumes you know how to measure what you build. After Part III you pick among Parts IV through VIII in whatever order matches what you are building, and every path converges on Part IX before the projects.

flowchart TB
    p1["Part I<br/>The stack"] -- "in order" --> p2["Part II<br/>Documents"]
    p2 -- "in order" --> p3["Part III<br/>Retrieval and evaluation"]
    p3 --> pick(["pick your path"])
    pick --> p4["Part IV<br/>Workflows<br/>and agents"]
    pick --> p5["Part V<br/>Analytics on<br/>text and tables"]
    pick --> p6["Part VI<br/>Customizing<br/>models"]
    pick --> p7["Part VII<br/>Beyond text"]
    pick --> p8["Part VIII<br/>Structured<br/>knowledge"]
    p4 --> p9["Part IX<br/>Production discipline"]
    p5 --> p9
    p6 --> p9
    p7 --> p9
    p8 --> p9
    p9 --> p10["Part X<br/>Projects"]
Figure 1: The reading paths through the book. Parts I through III are the spine and are read in order; from there, Parts IV through VIII are independent capabilities you can read in any order that matches what you are building; every path converges on Part IX before the Part X projects.

If you arrive needing one specific system quickly, here are five common goals and the smallest chapter sequence that reaches each. These sequences deliberately compress the default path: each assumes the Part I substrate and takes from the rest of the spine only what its goal strictly requires, but none of them drops Chapter 9, the evaluation toolkit. Every chapter in these sequences carries its own evaluation section as well, so measurement begins before you reach Chapter 9 itself.

Goal Minimal chapter sequence
Q&A over a corpus of documents 5, 6, 7, 8, 9
Automated ticket triage and routing 2, 3, 9, 11, 23
Natural-language answers over a data warehouse 3, 14, 9
A model fine-tuned to your domain 15, 16, 17, 9
A production chatbot a stakeholder can use 7, 9, 23, 24, 25

Every chapter from Chapter 2 onward ends with three exercises: a small set of multiple-choice questions, a build lab that extends the chapter’s notebook, and an evaluation lab that asks you to measure something. The evaluation lab is short and non-skippable, because it is where the discipline of measurement takes hold.

A note on AI coding tools

Most readers of this book will use an AI coding tool (Claude Code, Cursor, GitHub Copilot, Aider) for at least some of the labs. The book’s position is the one a math class holds on calculators: the tool is welcome, and the skills taught here are the ones that keep you in charge of it, knowing what to ask for and whether what comes back is right.

Two recurring callouts apply that position in the chapters. “With an AI coding tool” marks places where delegating a portion of the work to the tool will accelerate your learning without replacing it (drafting a Pydantic schema; refactoring a function you wrote by hand). “Don’t outsource this” marks places where letting the tool decide would erase the thinking the chapter is teaching (choosing a metric; reading a confusion matrix; deciding whether a number is good enough). The Build lab at the end of a chapter is a place where the tool is welcome; in the Evaluate lab it may still write the loop and the table, but choosing the metric and reading the result stay yours. Appendix H has the full guide.

What you need to start

You need three things: Python 3.11 or newer, a code editor, and an OpenRouter API key. Most of the book runs on a normal laptop, and Chapter 4 covers GPUs for the two chapters that want one.

ImportantBefore you run anything

Appendix A is the complete setup walkthrough: Miniforge, the book’s companion repository with all the code and data, VS Code, your API key, and a one-command check that verifies the whole chain. It takes about twenty minutes. Chapter 1 has nothing to run, so do Appendix A before starting Chapter 2; every chapter after that assumes it.

We are glad you are here, and we will see you in Chapter 1.