Concepts / Introduction to Machine Learning Practice

Introduction to Machine Learning Practice

The book is for current and aspiring machine learning practitioners who want to implement solutions to real-world machine learning problems, and it also serves scientists, researchers, and commercial data scientists.

  • Programming

Why Reading the Audience Statement Matters

Before you invest hours in a technical book, it helps to know who it was written for. A book can target experts who already know the field, beginners who know nothing yet, or people somewhere in between. The opening description of this book answers that question directly. It names the readers it serves and the background it expects, so reading it carefully saves time and sets realistic expectations.

This article also introduces the central idea that the rest of the course builds on: machine learning is a field that trains algorithms to make predictions or decisions based on data. You will see that idea split into two moments, training and prediction, and you will watch a small program change state as it moves from one to the other.

Who This Book Is Written For

The book is aimed at two overlapping groups. The first is current machine learning practitioners, meaning people who already work in the field. The second is aspiring practitioners, meaning people who want to enter it. What unites both groups is a practical goal: they want to implement solutions to real-world machine learning problems. The book is therefore oriented toward building working systems, not only toward understanding ideas in the abstract.

The source also names other readers whose work the methods will serve. Scientists and researchers can use the approaches it introduces, and so can data scientists working on commercial applications. Taken together, these statements describe an audience defined by purpose rather than job title. The defining question is whether you need to take a machine learning problem from a description to a functioning application.

What the Book Assumes You Already Know

The most important feature of the audience description is what it leaves out. The book is introductory, and it explicitly requires no previous knowledge of machine learning or artificial intelligence. You do not need to have studied the theory, trained a model, or read about AI before starting. The book's own steps are meant to be the route from zero to a working application.

Python, NumPy, and matplotlib Versus scikit-learn

The source does recommend some preparation, and it is phrased carefully. It says you will get the most out of the book if you are somewhat familiar with Python and with the NumPy and matplotlib libraries. The wording is about getting the most from the book, not about a hard entry requirement. Python is the language the book uses throughout, so comfort with Python matters most. NumPy and matplotlib are named as additional libraries whose familiarity is helpful.

These recommended skills are different from the book's main library focus. scikit-learn is the library the book concentrates on, and it is taught inside the book rather than assumed as prior knowledge. In other words, you are expected to arrive comfortable with Python and possibly NumPy and matplotlib, but you are not expected to arrive already knowing scikit-learn.

Checking a Reader Profile Against the Audience

The audience statement becomes useful when you apply it to a specific person. The three profiles below are illustrations written for this article, not taken from the source. Each one is checked against what the source actually says about audience and preparation.

Worked example

Matching three reader profiles to the stated audience

Three readers are considering the book. Decide whether each profile matches its stated audience and preparation. Profile A: a software engineer who writes Python daily but has never used NumPy or matplotlib and wants to build a model for a product feature. Profile B: a biology researcher who knows machine learning well from a previous project but has never written Python. Profile C: a student with no machine learning background who has never programmed and wants to understand the field before doing anything else.

  1. 1
    Check the target groups

    Profile A wants to build a working model for a product, which matches the goal of implementing solutions to real-world problems. Profile B is a researcher with a practical problem, which falls under the readers the source says it also serves. Profile C wants to understand the field, but the book is oriented toward building working systems, so the fit is weaker on purpose.

  2. 2
    Check the prior knowledge

    The book requires no previous machine learning or AI knowledge, so Profile C's lack of machine learning background is not a barrier. Profile A and Profile B both lack some recommended preparation, but the source phrases that preparation as helpful for getting the most from the book, not as a hard requirement.

  3. 3
    Identify the real gap

    Profile A's gap is NumPy and matplotlib, which the source names as helpful but not required. Profile B's gap is Python, which the source calls the language the book uses throughout, so comfort with it matters most. Profile C's gap is programming in general, which sits closest to the recommended Python familiarity.

Result

Profile A matches the audience well and needs only light NumPy and matplotlib preparation. Profile B matches the purpose but should prioritize learning Python before starting. Profile C matches the no-prerequisite statement for machine learning, but should build Python comfort first to get the most from the book.

Machine Learning as Training and Prediction

Definition

Machine learning is a field of study that trains algorithms to make predictions or decisions based on data. Its central activity is training an algorithm so that it can later make predictions or decisions. Nearly every idea in the course is a refinement of this definition.

The definition contains two distinct moments. Training adjusts an algorithm using data, and the result is a trained model that holds what was learned. Prediction applies that trained model to a new case whose answer is not yet known. Training uses data that already has answers to shape the algorithm. Prediction uses the shaped algorithm on a case whose answer is unknown. Mixing these two moments up is one of the most common early confusions.

Labeled examplesdata with known answersNew caseanswer not yet knownTrainingalgorithm adjusted by dataPrediction ordecisionoutput for the new caseTrained modelholds what was learnedshapesproducesapplied to new caseinput
During training, labeled examples go into the algorithm and a trained model comes out. During prediction, the trained model is applied to a new case that was not part of training, producing a prediction or decision.

A Threshold Learner, Step by Step

To make the two steps concrete, consider a deliberately simple algorithm. It learns a single number, a threshold, from labeled examples. Each example is a pair of a number and a label, where the label is either low or high. Study the code first, then follow how the training step changes the state of the program. This example was written for this article and is not taken from the source.

Code walkthrough
labeled_examples = [(1, 'low'), (2, 'low'), (3, 'low'), (8, 'high'), (9, 'high'), (10, 'high')]
threshold = None

def train(examples):
    lows = [x for x, label in examples if label == 'low']
    highs = [x for x, label in examples if label == 'high']
    return (max(lows) + min(highs)) / 2

def predict(value):
    return 'high' if value >= threshold else 'low'

threshold = train(labeled_examples)
print(threshold)
print(predict(5))
print(predict(7))
  1. 1
    Line 1 creates six labeled examples. The data is fixed and never changes during the program.
  2. 2
    Line 2 sets threshold to None. Before training, the variable holds no learned number.
  3. 3
    The train function separates the lows from the highs and returns their midpoint between the largest low and the smallest high.
  4. 4
    The predict function uses the threshold variable. It does not look at labeled_examples at all.
  5. 5
    The line threshold = train(labeled_examples) runs training and stores the learned number in threshold.
  6. 6
    print(threshold) shows 5.5, the learned value.
  7. 7
    predict(5) returns low because 5 is below 5.5, and predict(7) returns high because 7 is at or above 5.5.
  • labeled_examples holds the training data, each pair giving a number and its known label
  • threshold starts as None, meaning no learned value exists yet
  • train reads the examples and returns a number between the largest low value and the smallest high value
  • predict compares a new value against the stored threshold
  • The call to train is the training step; the calls to predict are the prediction step
Output
5.5
low
high
Rule

The formula is simply the midpoint between the largest low example and the smallest high example, which here are 3 and 8. The learned threshold $t$ is 5.5. This is the trained model in this example: a single stored number that captures what training found in the data.

Tracing the Program State Before and After Training

The clearest way to see what training does is to compare the program's state before and after the training step. The examples themselves never change. What changes is the threshold variable, which goes from holding no value to holding a learned number.

Before
labeled_examples = [(1, 'low'), (2, 'low'), (3, 'low'), (8, 'high'), (9, 'high'), (10, 'high')]
threshold = None

threshold holds None, so no learned value exists yet

After
labeled_examples = [(1, 'low'), (2, 'low'), (3, 'low'), (8, 'high'), (9, 'high'), (10, 'high')]
threshold = train(labeled_examples)  # stores 5.5

threshold holds 5.5, a learned number that predict can read

examplessix labeled pairsexamplessix labeled pairsthresholdNonethreshold5.5
The examples stay the same across training. Only the threshold variable changes, moving from no value to the learned number 5.5. Later predictions read that stored number.

Once the number exists, the prediction step can use it on any new value without looking at the original examples again. The calls predict(5) and predict(7) both read the same stored threshold. Five is below 5.5 and returns low, while seven is above it and returns high.

Mistakes Beginners Make About Learning from Data

  • Common mistake

    Thinking the model is programmed with explicit rules written by a person

    What it looks like

    Assuming someone must type in the rule 'above 5.5 means high' before the program can classify anything

    Why it fails

    In the threshold example, the number 5.5 was not typed in by a person. It was found by training on labeled examples.

    Do this instead

    Ask what data the algorithm was trained on, and how the learned value came out of that data.

  • Common mistake

    Confusing training data with the new case used for prediction

    What it looks like

    Testing predict on one of the six original examples and calling that a prediction on unknown data

    Why it fails

    Prediction is defined as applying the trained model to a case whose answer is not yet known, so the new case must differ from the training data.

    Do this instead

    Keep training examples and new cases separate when thinking about what a system actually does.

  • Common mistake

    Assuming the examples are changed or consumed by training

    Why it fails

    Training reads the examples. In the threshold example, the examples stay the same and only the threshold variable changes.

  • Common mistake

    Assuming a learned value exists before training runs

    What it looks like

    Calling predict before threshold is set, when it still holds None

    Why it fails

    Before training, the variable holds no learned number, so the prediction step has nothing meaningful to read.

    Do this instead

    Confirm that the training step has run and stored its result before expecting predictions.

  • Common mistake

    Believing that machine learning requires prior knowledge of AI before starting the book

Predicting the Output of a New Input

What do you think happens?

Using the threshold program from earlier, what does predict(7) return, and why?

Reveal answer
Answer:

It returns 'high'.

The trained threshold stored in the program is 5.5. Since 7 is greater than or equal to 5.5, predict returns 'high'. The prediction step reads the stored threshold and never looks at the original examples again.

EASY

Without changing the code, predict what predict(4) returns and explain which value the prediction step compares against. Then explain why the training examples are not needed at the moment of prediction.

Hints
  • Compare 4 with the stored threshold, not with the training examples.
  • The threshold is 5.5 after training has run.
  • Think about what the prediction step reads from program state.

Key Takeaways

  • The book is for current and aspiring machine learning practitioners who want to build working solutions to real-world problems, and it also serves scientists, researchers, and commercial data scientists.
  • The book is introductory and requires no previous knowledge of machine learning or AI. It recommends being somewhat familiar with Python, NumPy, and matplotlib, with Python used throughout, while scikit-learn is taught within the book rather than assumed.
  • Machine learning trains algorithms to make predictions or decisions based on data. Training uses labeled examples to produce a trained model, and prediction applies that model to a new case whose answer is unknown.
  • In a program, training changes state: a variable such as threshold moves from holding no value to holding a learned number, which the prediction step then reads without revisiting the examples.
  • Common beginner mistakes include assuming a person writes the rules explicitly, confusing training data with new cases, and assuming a learned value exists before training runs.

Related concepts

More concepts starting with I