Contents/ Part XVII · Introducing Machine Learning/ Chapter 108

What Is Machine Learning?

Machine learning is how computers learn patterns from data instead of following hand-written rules. This opener maps the whole field: the three learning paradigms, supervised, unsupervised, and reinforcement, the split between classification and regression, and how the machine-learning mindset differs from the statistics you already know. Every idea is run in code on one real customer table.

⏱️ ~18 min read
🐍 Notebook included
📊 Chapter 108

For most of this book a human wrote the rule: compute a mean, fit a line, run a test. Machine learning flips that around, you show the computer examples and it learns the rule itself, then applies it to data it has never seen. That single shift powers recommendation feeds, fraud alerts, medical triage, and the large language models behind modern AI.

ML
Machine learning is the study of algorithms that improve at a task by learning from data rather than being explicitly programmed. Its three great families are supervised (learn from labeled examples), unsupervised (find structure with no labels), and reinforcement (learn a policy from reward).
🤖
The chapter in one line

If your data has a label to predict, it is supervised (classification for a category, regression for a number); if it has no label, it is unsupervised; if an agent learns from reward, it is reinforcement learning.

1

The Three Paradigms of Learning

Almost every machine-learning method belongs to one of three families, distinguished by what kind of feedback the algorithm gets. This one picture is the map for the rest of the section.

Three ways a machine can learn SUPERVISED learn from labeled examples features (age, spend…) label model learns f: X → y then predicts the label for new, unlabeled rows UNSUPERVISED find structure, no label the algorithm groups similar rows into clusters on its own REINFORCEMENT learn a policy from reward agent environment action reward try an action, see the reward, repeat, and improve the policy games, robotics, RLHF

The vast majority of applied work is supervised, because so many valuable questions come with labeled history: past emails marked spam or not, past loans that defaulted or not, past customers who churned or not. Unsupervised learning is the tool for exploration when no label exists, and reinforcement learning shines when an agent must act in a changing environment. The notebook runs one small example of each on the same data.

2

Supervised Learning: Classification vs Regression

Supervised learning always has the same shape: a table of features (the inputs, written X) and a label (the target, written y). The model learns the mapping from X to y on training examples, then predicts y for new rows. It splits in two by the type of the label.

Two flavors of supervised learning Classification → a category stayed churned a boundary separates the classes Regression → a number a line predicts a continuous value

In the notebook, a LogisticRegression classifier predicts the category churned (yes/no) and reaches 77% accuracy on customers it never trained on; a LinearRegression regressor predicts the number monthly_spend and scores R² = 0.83 on the test set. Same three-step recipe every time, split, fit, evaluate on held-out data, changing only the kind of answer. And note the golden rule already in play: we always judge a model on data it has not seen, because memorizing the training set is not learning.

3

Statistics vs Machine Learning

You have already done machine learning, a fitted regression is a supervised model. What changes in ML is the emphasis: from explaining a process to predicting new outcomes.

Classical statisticsMachine learning
Main goalinference: explain, with uncertaintyprediction: generalize to new data
Key questionwhich effects are real, and how big?how accurate is it on unseen cases?
Prized outputcoefficients, p-values, intervalsheld-out accuracy, error, loss
Validationmodel assumptions, diagnosticstrain / test split, cross-validation
Typical toolstatsmodelsscikit-learn

The notebook makes this vivid on the churn data: the statistics view fits a logistic model and reads its coefficients, short tenure and frequent support calls significantly raise churn (tiny p-values); the machine-learning view cross-validates the same model and reports a single number, 79% accuracy on unseen customers. Neither is better, they answer different questions, and a strong practitioner moves fluently between "why?" and "how well will it predict?"

4

Real-World Example: Supervised and Unsupervised on One Table

A telecom has 600 customers with six numeric features and a churn label. The same table answers a supervised question (who will churn?) and an unsupervised one (what natural segments exist?), the two most common tasks in commercial ML.

📂 Dataset · what-is-machine-learning--customers.xlsx

One row per customer with age, income_k, tenure_months, num_products, monthly_spend, and support_calls, plus the label churned (1 = left last quarter, 0 = stayed).

Run unsupervised on the numeric features and KMeans recovers three clean segments, with no label at all:

K-means found 3 customer segments (no label used) annual income (thousands of dollars) monthly spend 4070100130 budget standard premium
Discovered segmentSizeAvg income / spendChurn rate
Budget269~40k / $44, 1.5 products, 15 mo50%
Standard242~73k / $61, 2.4 products, 39 mo10%
Premium89~101k / $90, 4.5 products, 50 mo0%

The two tasks reinforce each other. Unsupervised clustering found the segments blind, yet they line up perfectly with the supervised label: the budget segment (short tenure, few products) carries essentially all the churn risk, while the premium segment barely leaves. That is the practical payoff of the taxonomy, one dataset, two lenses, and a clear action: focus retention on the budget segment.

5

The Paradigms in Modern AI

The three families are not just textbook categories, they are the scaffolding of every frontier AI system. The same words, scaled up with deep neural networks and enormous datasets, describe how today's models are built.

Paradigm (this chapter)At the frontier it becomesExample
SupervisedLabeled deep learningimage classifiers, medical diagnosis from scans
Unsupervised / self-supervisedPretraining on raw dataan LLM learning to predict the next token on the web
ReinforcementLearning from feedbackgame agents; RLHF aligning chatbots to human preference
Regression / classificationThe two output headsa network ending in a number or a class probability
🤖
Why this matters for AI research

A modern large language model is a tour of all three paradigms at once. It is pretrained by self-supervised learning, predicting the next word on trillions of tokens with no human labels, which is unsupervised learning in disguise. It is then fine-tuned with supervised examples of good answers, and finally aligned with reinforcement learning from human feedback (RLHF), an agent optimizing a reward built from human preferences. The vocabulary of this one chapter, features and labels, classification and regression, clustering, reward, is exactly the language you need to read a frontier AI paper.

🐍

Run all three paradigms in Python

The companion notebook trains a churn classifier and a spend regressor with scikit-learn, finds customer segments with K-means, teaches a reinforcement-learning agent to pick the best offer from reward, and contrasts the statsmodels inference view with the cross-validated ML view, every cell explained.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub

View opens the rendered notebook instantly (no setup). Open in Colab runs & edits it live in your browser. To run locally, install numpy, pandas, scikit-learn, statsmodels, matplotlib, seaborn, and openpyxl.

🎓 Key Takeaways

  • Machine learning learns rules from data instead of being programmed with them, then applies them to unseen cases.
  • Three paradigms: supervised (labeled examples), unsupervised (structure, no label), reinforcement (a policy from reward).
  • Supervised splits by label type: classification predicts a category, regression predicts a number, same split-fit-evaluate recipe.
  • Always evaluate on held-out data: a model that only fits the training set has memorized, not learned.
  • Statistics vs ML is a difference of emphasis: inference (explain) versus prediction (generalize); frontier AI uses all three paradigms at once.
6

Practice Challenges

Five short challenges on the customer table. Try them with scikit-learn before checking the solutions.

1

Features vs label

Separate the input features from the target and print the shape of each.

Hint: X = df[feat], y = df["churned"].
2

Train / test split and accuracy

Hold out 30%, train a logistic classifier, and report accuracy on the unseen part.

Hint: train_test_split then accuracy_score.
3

Regression instead

Predict monthly_spend (a number) and report the test R².

Hint: LinearRegression().score(X_test, y_test).
4

Cluster into segments

Run K-means with k = 3 on the numeric features; print the mean income and spend per cluster.

Hint: KMeans(n_clusters=3).fit_predict(...) then groupby.
5

Explain vs predict

Fit a statsmodels logit to find the strongest churn driver, then cross-validate for a prediction score.

Hint: read the coefficients, then cross_val_score(..., cv=5).
Check your work

A fully-worked solutions notebook walks through all five challenges, each verified in code. Try them yourself first, then compare.

📓 View Solutions ▶ Open Solutions in Colab ⬇ View / Download on GitHub
7

Quiz: Test Yourself

Eight quick questions on the machine-learning taxonomy. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved, so you can hop back to the chapter and return anytime.

➡️
Up next

You now know what the field contains. The Machine Learning Workflow turns the taxonomy into a disciplined process, train/validation/test splits, cross-validation, hyperparameter tuning, pipelines, and the leakage traps that quietly inflate every beginner's accuracy.