\

Chapter 1: The Machine Learning Landscape

17 min read

Notes for Chapter 1

When you hear “Machine Learning,” what pops into your head? Robots? Terminators? Maybe a friendly butler? The book nails it – it’s not just sci-fi; it’s already here. Think about the spam filter. That was one of the first really big ML applications that touched millions. It learned, from examples of spam and non-spam (or “ham,” as we call it), to tell the difference. And it got so good that we barely notice it anymore. That’s the hallmark of good ML – it just works.

This chapter aims to clarify what ML is, why it’s useful, and give you a “map” of the ML continent: supervised vs. unsupervised, online vs. batch, instance-based vs. model-based. We’ll also touch on the typical project workflow and some common challenges.

(Page 2: What Is Machine Learning?)

Alright, so what is it? The book gives a great, simple definition:

“Machine Learning is the science (and art) of programming computers so they can learn from data.”

The key here is “learn from data.” Instead of you, the programmer, writing explicit rules for every single scenario, you show the computer a bunch of examples, and it figures out the patterns itself.

Arthur Samuel, a pioneer back in 1959, said it’s the “field of study that gives computers the ability to learn without being explicitly programmed.” Think about that – without explicit programming. That’s the magic.

Then there’s Tom Mitchell’s more engineering-focused definition from 1997, which is super useful for grounding this:

“A computer program is said to learn from experience E with respect to some task T and some performance measure P, if its performance on T, as measured by P, improves with experience E.”

Let’s break that down with our spam filter:

  • Task T: Flagging spam emails.
  • Experience E: The training data – thousands of example emails, each labeled as “spam” or “ham.”
  • Performance Measure P: How well does it do the task? Maybe it’s accuracy – the percentage of emails it correctly classifies.

So, if our spam filter gets better at correctly identifying spam (higher accuracy P) after being shown more examples of emails (more experience E), then it’s learning!

And the book rightly points out: downloading all of Wikipedia doesn’t make your computer “learn” in the ML sense. It has more data, sure, but it’s not suddenly better at, say, translating languages or identifying cats in pictures, unless you use that data to train it for a specific task.

(Page 3-4: Why Use Machine Learning?)

So, why bother? Why not just write the rules, like we’ve always done in traditional programming? The book uses the spam filter example (Figure 1-1 vs 1-2), and it’s perfect.

  1. Problems too complex for traditional rules: Imagine trying to write rules for spam. “If email contains ‘4U’, ‘credit card’, ‘free’, ‘amazing’…” Okay, a start. But spammers get smart. They start writing “For U” or using images. Your list of rules would become a monster – thousands, maybe millions of lines long, and a nightmare to maintain (Figure 1-1).
    • An ML spam filter, on the other hand, learns which words and phrases are good predictors by looking at frequencies in spam vs. ham (Figure 1-2). It’s often shorter, easier to maintain, and more accurate.
  2. Adapting to changing environments: When spammers change tactics (“For U” instead of “4U”), a traditional filter needs you to manually update the rules. An ML system, especially an online learning one (we’ll get to that), can see these new patterns emerging in user-flagged spam and automatically adapt (Figure 1-3). It keeps learning!
  3. No known algorithm: Think about speech recognition. How would you even begin to write rules to distinguish “one” from “two” for every voice, accent, in noisy environments, across dozens of languages? It’s incredibly hard. But give an ML algorithm enough recordings of people saying “one” and “two,” and it can learn to distinguish them.
  4. Helping humans learn (Data Mining): This is a fascinating one (Figure 1-4). Sometimes, we train an ML model, and then we can peek inside (though it’s tricky for some complex models) to see what it learned. A spam filter might reveal surprising combinations of words that are highly predictive of spam. This can give us new insights into complex problems by finding patterns we wouldn’t have spotted.

(Page 5-6: Examples of Applications)

The book lists a ton, and this really shows the breadth of ML:

  • Image Classification (CNNs): Identifying products on a production line, detecting tumors in brain scans (this is more semantic segmentation – classifying every pixel).
  • Natural Language Processing (NLP): Classifying news articles, flagging offensive comments, summarizing documents, chatbots (NLU, question-answering). These often use RNNs, CNNs, or more recently, Transformers.
  • Regression (predicting values): Forecasting company revenue. This can use Linear Regression, SVMs, Random Forests, Neural Networks.
  • Speech Recognition: Making your app react to voice commands.
  • Anomaly Detection: Detecting credit card fraud.
  • Clustering (Unsupervised): Segmenting customers based on purchases for targeted marketing.
  • Data Visualization/Dimensionality Reduction: Taking high-dimensional data and making it understandable in 2D or 3D.
  • Recommender Systems: Suggesting products you might like.
  • Reinforcement Learning (RL): Building intelligent bots for games, like AlphaGo that beat the world Go champion.

This isn’t exhaustive, but it gives you a taste of the sheer power and versatility.

(Page 7-9: Types of Machine Learning Systems - The Big Picture)

Okay, now for the “map of the ML continent.” We can categorize ML systems based on a few key criteria. These aren’t mutually exclusive; a system can be a mix.

1. Based on Human Supervision during Training:

  • (Page 8) Supervised Learning: This is probably the most common. The “supervision” comes from the fact that your training data includes the desired solutions, called labels (Figure 1-5). You show the system an email AND tell it “this is spam.” You show it a picture of a cat AND tell it “this is a cat.”

    • Classification: The task is to predict a category. Spam or ham? Cat or dog? Figure 1-5 (spam classification) is a classic example.
    • Regression: The task is to predict a numerical value. What’s the price of this car given its mileage, age, brand (these are features or predictors)? (Figure 1-6). The “label” here is the actual price.
    • A quick note on terminology (page 8): An attribute is a data type (e.g., “mileage”). A feature is often an attribute plus its value (e.g., “mileage = 15,000”). People often use them interchangeably, but it’s good to know the nuance.
    • The book lists some key supervised algorithms we’ll cover: k-Nearest Neighbors, Linear Regression, Logistic Regression (often used for classification despite “regression” in its name!), SVMs, Decision Trees, Random Forests, and Neural Networks.
  • (Page 9-12) Unsupervised Learning: Here, the training data is unlabeled (Figure 1-7). There’s no “teacher” providing answers. The system tries to find patterns and structure in the data on its own.

    • (Page 10) Clustering: Trying to find natural groupings in the data. For example, grouping your blog visitors into different segments based on their behavior (Figure 1-8). You don’t tell it the groups beforehand; it discovers them. Algorithms include K-Means, DBSCAN, Hierarchical Cluster Analysis (HCA).
    • (Page 11) Visualization & Dimensionality Reduction: Taking complex, high-dimensional data and creating a 2D or 3D plot (Figure 1-9, t-SNE example). This helps us understand the data. Dimensionality reduction aims to simplify the data by merging correlated features (e.g., car mileage and age into “wear and tear”) or dropping less important ones, without losing too much information. This is called feature extraction. It can make subsequent learning faster and sometimes better. PCA, Kernel PCA, LLE are examples.
    • (Page 12) Anomaly Detection / Novelty Detection: Spotting unusual instances. Anomaly detection is about finding things that look different from most of the data (e.g., fraud detection, Figure 1-10). Novelty detection is similar but assumes your training data is “clean” and you want to find things different from anything seen in training.
    • (Page 13) Association Rule Learning: Discovering relationships between attributes in large datasets. E.g., people who buy barbecue sauce and potato chips also tend to buy steak.
  • (Page 13) Semisupervised Learning: This is a middle ground. You have a lot of unlabeled data and a little bit of labeled data (Figure 1-11). The system uses both. Think of Google Photos: it clusters faces (unsupervised), then you label a few faces (“That’s Aunt May”), and it can then label Aunt May in many other photos (supervised part). Deep Belief Networks (DBNs) using Restricted Boltzmann Machines (RBMs) are an example.

  • (Page 14) Reinforcement Learning (RL): This is a different beast altogether! The learning system, called an agent, observes an environment, selects and performs actions, and gets rewards (or penalties) in return (Figure 1-12). It learns the best strategy, called a policy, to maximize its cumulative reward over time. Think training a robot to walk, or AlphaGo learning to play Go. It learns by trial and error, essentially.

2. Based on Incremental Learning (On-the-fly):

  • (Page 15) Batch Learning (Offline Learning): The system is trained using all available data at once. It takes time and resources. Once trained, it’s launched and doesn’t learn anymore; it just applies what it learned. If you want it to learn about new data (e.g., new types of spam), you have to retrain it from scratch on the full dataset (old + new). This can be automated (as in Figure 1-3), but it’s still a full retrain. This is fine for many things, but not if you need to adapt rapidly or have massive datasets.

  • (Page 15-16) Online Learning (Incremental Learning): The system is trained incrementally by feeding it data instances sequentially, either individually or in small groups called mini-batches (Figure 1-13). Each learning step is fast and cheap. This is great for:

    • Systems needing rapid adaptation (e.g., stock price prediction).
    • Systems with limited computing resources (once it learns from a data instance, it might not need to store it anymore).
    • Handling huge datasets that can’t fit in memory (called out-of-core learning, Figure 1-14). It loads a chunk, trains, loads the next chunk, trains, etc. The book notes, “Think of it as incremental learning,” which is a good way to avoid confusion, as out-of-core is often done offline.
    • A key parameter here is the learning rate: how quickly it adapts. Too high, and it forgets old patterns quickly. Too low, and it learns slowly and might be less sensitive to noise or outliers.

3. Based on How They Generalize:

This is about how systems make predictions on new, unseen data.

  • (Page 17-18) Instance-Based Learning: The system learns the training examples by heart. Then, when it sees a new instance, it compares it to the stored examples using a similarity measure and makes a prediction based on the most similar known instances. For example, in Figure 1-15, the new instance (cross) is classified as a triangle because most of its nearest neighbors are triangles. k-Nearest Neighbors is a classic example.

  • (Page 18-22) Model-Based Learning: The system builds a model from the training examples and then uses that model to make predictions. This is like a scientist observing data and building a theory. The book uses a great example: predicting life satisfaction based on GDP per capita (Table 1-1, Figure 1-17).

    1. You select a type of model – say, a linear model (Equation 1-1: life_satisfaction = θ₀ + θ₁ × GDP_per_capita). This is model selection.
    2. This model has parameters (θ₀ and θ₁ – theta-zero and theta-one). By tweaking these, you get different lines (Figure 1-18).
    3. How do you find the best parameters? You need a performance measure. For linear regression, it’s often a cost function that measures how far the model’s predictions are from the training examples. The goal is to minimize this cost.
    4. The learning algorithm (e.g., Linear Regression algorithm) takes your training data and finds the parameter values (θ₀, θ₁) that make the model best fit the data. This is called training the model (Figure 1-19).
    5. Once trained (e.g., θ₀ = 4.85, θ₁ = 4.91 × 10⁻⁵), you can use the model to make predictions on new data (e.g., Cyprus’s life satisfaction, page 21). The code snippet on page 21-22 shows how you’d do this with Scikit-Learn. And then it shows how simple it is to swap in an instance-based algorithm like k-Nearest Neighbors!

(Page 23-29: Main Challenges of Machine Learning)

So, you select an algorithm and train it. What can go wrong? The book says: “bad algorithm” and “bad data.”

Let’s start with “Bad Data”:

  • (Page 23) Insufficient Quantity of Training Data: Most ML algorithms need a lot of data to work well. Thousands for simple problems, millions for complex ones like image recognition. The “Unreasonable Effectiveness of Data” paper (page 24, Figure 1-20) showed that even simple algorithms can perform incredibly well if given enough data. Data often trumps a fancy algorithm, but getting more data isn’t always cheap or easy.
  • (Page 25) Nonrepresentative Training Data: Your training data must be representative of the new cases you want to generalize to. If you train a model on life satisfaction vs. GDP using only rich countries, it won’t predict well for poor countries (Figure 1-21).
    • This can happen due to sampling noise (if your sample is too small and just happens to be unrepresentative by chance) or sampling bias (if your sampling method is flawed).
    • The Literary Digest poll example (page 26) is a classic case of sampling bias – they polled wealthier people, who leaned Landon, but Roosevelt won. And nonresponse bias – only certain types of people responded.
    • Want to build a funk music video recognizer by searching YouTube? Your results will be biased towards popular artists.
  • (Page 26) Poor-Quality Data: Errors, outliers, noise. “Garbage in, garbage out.” Data cleaning is a huge part of a data scientist’s job! You might discard outliers, fix errors, or decide how to handle missing feature values (ignore the feature, ignore the instance, fill it in – e.g., with the median).
  • (Page 27) Irrelevant Features: If your training data has too many irrelevant features (and not enough relevant ones), the system will struggle. Feature engineering is critical:
    • Feature selection: Choosing the most useful features.
    • Feature extraction: Combining existing features into a more useful one (like we saw with dimensionality reduction).
    • Creating new features: Sometimes you need to gather new data or derive new features.

Now for “Bad Algorithm” (or more accurately, issues with the model itself):

  • (Page 27-29) Overfitting the Training Data: This is a HUGE one. The model performs great on the training data but poorly on new, unseen data. It’s like it memorized the training data, including its noise and quirks, instead of learning the underlying general pattern (Figure 1-22).

    • Imagine your life satisfaction model learns that countries with a ‘W’ in their name are happier based on your training data (New Zealand, Norway, Sweden). This is just a chance pattern in your data, not a real rule!
    • Solutions (page 28):
      • Simplify the model: Choose one with fewer parameters (e.g., linear instead of high-degree polynomial), reduce features, or constrain the model.
      • Gather more training data.
      • Reduce noise in the training data (fix errors, remove outliers).
    • Regularization (page 28-29): Constraining a model to make it simpler and reduce overfitting. For our linear model, if we force the slope (θ₁) to be small, it makes the line flatter and less likely to chase noise (Figure 1-23). The amount of regularization is controlled by a hyperparameter.
    • Crucial distinction (page 29): A model parameter (like θ₀, θ₁) is something the learning algorithm tunes. A hyperparameter is a parameter of the learning algorithm itself (e.g., the amount of regularization to apply). You set hyperparameters before training.
  • (Page 29) Underfitting the Training Data: The opposite of overfitting. Your model is too simple to learn the underlying structure of the data. A linear model for life satisfaction might underfit because reality is more complex (Figure 1-21 showed this too – the linear model wasn’t great for very rich or very poor countries).

    • Solutions:
      • Select a more powerful model (more parameters).
      • Feed better features to the algorithm (feature engineering).
      • Reduce constraints on the model (e.g., reduce the regularization hyperparameter).

(Page 30-33: Stepping Back, Testing and Validating)

Phew! That was a lot. The book summarizes it well on page 30:

  • ML is about machines learning from data, not explicit rules.
  • Many types: supervised/unsupervised, batch/online, instance/model-based.
  • Typical project: Gather data, feed to algorithm. Model-based learns parameters to fit. Instance-based learns by heart.
  • Pitfalls: Bad data (too little, non-representative, noisy, irrelevant features) or bad model (overfitting/underfitting).

So, you’ve trained a model. How do you know if it will generalize to new cases? You can’t just “hope”!

  • Training Set and Test Set (Page 30): Split your data. You train on the training set. You evaluate on the test set (data the model has never seen). The error rate on the test set is called the generalization error (or out-of-sample error). This tells you how well it will likely do in the real world.

    • If training error is low but generalization error is high, you’re overfitting!
    • Common split: 80% train, 20% test (but depends on dataset size, as page 31 notes).
  • (Page 31) Hyperparameter Tuning and Model Selection:

    • What if you’re choosing between a linear model and a polynomial model? Or trying to find the best regularization hyperparameter? You can’t just try them all on the test set and pick the best. Why? Because then you’ve tuned your model and hyperparameters to that specific test set. It might not perform well on other new data. You’ve essentially “used up” your test set.
    • Holdout Validation: The solution! Split your original training data further. Keep some aside as a validation set (or dev set).
      1. Train various models (with different hyperparameters, or different model types) on the reduced training set (full training set - validation set).
      2. Evaluate them on the validation set. Pick the best one.
      3. Now, train your best model (with its best hyperparameters) on the full original training set (including the validation set). This is your final model.
      4. Finally, evaluate this final model on the test set to get an estimate of its true generalization error.
    • Cross-validation is mentioned as a way to deal with small validation sets by using many small validation sets. More robust, but takes longer.
  • (Page 32) Data Mismatch: What if your training data (e.g., flower pictures from the web) isn’t perfectly representative of your production data (e.g., flower pictures taken by your mobile app)?

    • Crucial rule: Your validation set and test set must be as representative of the production data as possible. So, they should come from the app pictures.
    • If performance on the validation set is bad after training on web pictures, is it overfitting or data mismatch?
    • Andrew Ng suggests a train-dev set: a subset of the web (training) pictures held out.
      • If model does poorly on train-dev: it overfit the training web pictures. Simplify/regularize.
      • If model does well on train-dev but poorly on (app-based) validation set: it’s data mismatch. Try to make web images look more like app images (preprocessing).
  • (Page 33) No Free Lunch (NFL) Theorem: A humbling but important concept. There’s no single model that is a priori guaranteed to work best on all problems. If you make no assumptions about your data, any model is as good as any other.

    • A linear model might be best for one dataset, a neural network for another.
    • The only way to know for sure is to try them all (impossible!).
    • In practice, we make reasonable assumptions about the data and try a few suitable models.
  • (Page 33-34: Exercises) The chapter ends with a great set of exercises. I strongly encourage you to go through them. If you can answer these, you’ve got a solid grasp of this foundational material.


Okay! We’ve covered a massive amount of ground – the entire landscape of Machine Learning, really. We’ve defined what it is, why it’s a game-changer, explored the main types of systems, the process of building models, and the pitfalls to watch out for.

The key takeaways:

  • ML is about learning patterns from data.
  • The type of learning (supervised, unsupervised, etc.) depends on your data and your goal.
  • Data is king, but it needs to be good quality and representative.
  • Overfitting and underfitting are constant battles.
  • Always test your model on unseen data!

This chapter sets the stage. From here on out, we’ll be diving deeper into these concepts, with more math, more code, and more hands-on examples from the book.