Introduction to the Machine Learning Workflow
Welcome! In the previous chapters, we looked at what Artificial Intelligence (AI) and Machine Learning (ML) are. We learned that while traditional programming relies on a human writing specific instructions, Machine Learning allows a computer to find patterns in data and improve its performance over time. But how do we actually build a machine learning system? It doesn't happen by magic! It follows a specific, logical sequence of steps called the Machine Learning Workflow. Think of this as a "recipe" for teaching a computer how to solve a problem.
Machine Learning vs. Traditional Programming
Before we dive into the workflow, let’s quickly recap why we need it. In traditional programming, you provide the data and the rules (the code), and the computer gives you the result. In Machine Learning, you provide the data and the results (examples of what should happen), and the computer creates the rules (the model) for you.
Quick Note: If you need a refresher on the types of learning, remember that we use supervised learning (like k-nearest neighbours) when we have labeled examples, and unsupervised learning (like k-means) when we want the computer to find hidden groups on its own.
The 7-Step Machine Learning Workflow
To build a successful ML system, you must follow these seven essential steps. Don't worry if it seems like a lot—we will break them down one by one!
1. Gathering Data
This is the most important step. Without data, there is no learning! You need to collect examples related to the problem you want to solve.
Example: If you want to build a spam filter, you need to collect thousands of emails that are already marked as "Spam" or "Not Spam."
Analogy: Imagine you are studying for a Geography exam. Gathering data is like collecting all your textbooks, notes, and past-year papers. If you don't have enough materials, you can't study effectively!
2. Preparing Data
Raw data is often "messy." It might have missing values, errors, or be in a format the computer doesn't understand. In this step, we "clean" the data.
Key activities:
- Removing duplicate information.
- Fixing errors or missing values.
- Data Splitting: This is crucial! We usually split our data into two sets: a training set to teach the model, and a testing set to check how well it learned.
3. Choosing a Model
There are many different ML algorithms. Choosing the right one depends on your goal.
Example: If you are trying to classify objects into groups based on their closest neighbours, you might choose the \(k\)-nearest neighbours (KNN) model. If you are trying to find clusters in data without labels, you might choose \(k\)-means.
4. Training
This is where the "learning" happens. We feed our training data into the chosen model. The model looks for patterns or mathematical relationships in the data.
Concept: The goal of training is for the model to represent the patterns in the data accurately so it can make good guesses later.
5. Evaluating
Once the model is trained, we need to know if it's actually any good! We use the testing set (the data the model has never seen before) to see how accurately it performs.
Common Mistake: Never evaluate your model using the same data you used to train it. That would be like a teacher giving you the exact same questions from the textbook for the final exam—you might just be memorizing answers instead of actually understanding the subject!
6. Tuning Parameters
Most models have settings called parameters (or "hyperparameters") that control how the learning process works. If the evaluation shows the model isn't performing well, we adjust these settings.
Example: In \(k\)-nearest neighbours, the value of \(k\) (the number of neighbours to check) is a parameter. Changing \(k\) from \(k = 3\) to \(k = 5\) might make the model more accurate.
7. Making Predictions
This is the final goal! Once you are happy with the model's performance, you deploy it to solve real-world problems. You give it new data that has no labels, and the model uses the patterns it learned to give you an answer.
Example: Your spam filter is now live and correctly moves a brand-new "Win a Free Phone!" email into your Junk folder.
Summary of the Workflow
To help you remember the order, try this simple checklist: Gather \(\rightarrow\) Prepare \(\rightarrow\) Choose Model \(\rightarrow\) Train \(\rightarrow\) Evaluate \(\rightarrow\) Tune \(\rightarrow\) Predict
Key Takeaways for Students:
- Data Quality: Your model is only as good as the data you give it. If you give it "trash" data, you will get "trash" predictions!
- The Split: Always keep "Training" and "Testing" data separate to ensure your model can handle new, unseen information.
- Iteration: Tuning parameters is a normal part of the process. Very few models are perfect on the first try.
Did you know? In professional AI development, researchers often spend about 80% of their time just on Step 2 (Preparing Data)! Making sure data is clean and balanced is often more important than the actual algorithm used.
Quick Review: Which step involves adjusting the value of \(k\) in a \(k\)-means clustering algorithm?
Answer: Tuning parameters.