Chapter 2: Setting Up the Machine Learning Environment
Learn Machine Learning from very beginner to expert with detailed topic guidance, practical examples, practice exercises, and review questions.
What this chapter covers
This chapter contains 15 topics. Technical terms are followed by plain-language meanings in parentheses where they first appear. Code is included only when it naturally helps demonstrate the concept; architecture, workflow, governance, and comparison topics use practical scenarios instead.
2.1 Programming Foundations for Machine Learning
Programming Foundations for Machine Learning (basic programming ideas used to express data steps, rules, calculations, and model workflows). Machine-learning systems need a clear way to describe inputs, transformations, training steps, and evaluation steps without tying the course to one programming language.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A learner can describe a prediction workflow as: collect data, prepare inputs, train a model, evaluate it, then use it on new data.
Coding example
// Programming Foundations for Machine Learning
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Write a five-step machine-learning workflow in plain language and identify which step receives data and which step produces predictions.
2.2 Choosing a Machine Learning Runtime
Choosing a Machine Learning Runtime (selecting the local, cloud, browser-based, or managed environment where machine-learning work will run). The runtime provides computing resources, storage access, libraries, and execution support. The best choice depends on the project size, privacy needs, hardware, and collaboration requirements.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A small classroom project may run locally, while a large image model may use a managed cloud environment with GPU resources.
Coding example
// Choosing a Machine Learning Runtime
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Compare a local computer and a cloud runtime for cost, privacy, convenience, and available computing power.
2.3 Isolated Project Environments
Isolated Project Environments (keeping project dependencies separated so one project does not unexpectedly break another). Isolation helps make machine-learning work reproducible because each project can keep its own compatible dependency versions and settings.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
Project A may need one library version while Project B needs another. Separate environments prevent the two projects from interfering with each other.
Coding example
// Isolated Project Environments
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Explain why two machine-learning projects may need isolated environments even when they run on the same computer.
2.4 Notebook Environment Setup
Notebook Environment Setup (preparing an interactive document workspace where text, charts, calculations, and results can be explored together). Notebooks are useful for experiments, data exploration, teaching, and documenting how a result was produced.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A student can place a dataset summary, a chart, observations, and model results in one notebook so the full experiment is easy to review.
Coding example
// Notebook Environment Setup
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Design a notebook outline with sections for objective, data, exploration, model, evaluation, and conclusion.
2.5 Notebook Workflow Basics
Notebook Workflow Basics (organizing interactive experiments into clear, repeatable steps). A good notebook should be readable from top to bottom, avoid hidden dependencies, and clearly separate data loading, preparation, modelling, and evaluation.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A clean notebook first states the goal, then prepares the data, then tests a model, and finally records the result and limitations.
Coding example
// Notebook Workflow Basics
const tools = {
average: values => values.reduce((a,b)=>a+b,0)/values.length,
maximum: values => Math.max(...values)
};
const task = { tool: 'average', input: [4,7,9,10] };
const result = tools[task.tool](task.input);
console.log({ task, result });Code explanation
- The `tools` object acts as a small registry of allowed operations.
- The task explicitly names which tool should run and provides its input.
- The dispatcher selects the requested function and executes it.
- This pattern demonstrates controlled tool use and workflow orchestration without giving unrestricted access to arbitrary operations.
Expected result: The selected tool and its computed result are printed.
Practice exercise
List three practices that make a notebook easier for another learner to reproduce.
2.6 Interactive Lab Workspaces
Interactive Lab Workspaces (browser or desktop workspaces that combine notebooks, files, terminals, and project tools). An interactive lab workspace helps learners explore data and manage related resources in one place.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A learner can keep a dataset, experiment notes, charts, and model outputs within one project workspace.
Coding example
// Interactive Lab Workspaces
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Create a folder plan for data, notes, experiments, outputs, and documentation.
2.7 Development Editor for Machine Learning
Development Editor for Machine Learning (an editor or integrated development environment used to organize larger machine-learning projects). Editors help manage many files, search project content, run tests, inspect errors, and keep training and deployment logic organized.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A small experiment may begin in a notebook, then move into organized project files when it grows into a reusable application.
Coding example
// Development Editor for Machine Learning
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Explain when a learner might move from an exploratory notebook to a structured project editor.
2.8 Numerical Computing Tools
Numerical Computing Tools (tools designed for fast operations on arrays, vectors, matrices, and large groups of numbers). Machine learning performs many repeated numerical calculations, so efficient numerical tools are important for speed and scalability.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A dataset with thousands of rows can be processed as whole numerical arrays instead of handling each number manually.
Coding example
// Numerical Computing Tools
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Describe why processing an entire numerical array is usually better than manually working with one value at a time.
2.9 Tabular Data Tools
Tabular Data Tools (tools for working with rows, columns, missing values, categories, and joined datasets). Tabular tools are common in business and scientific machine learning because many datasets are organized as records with named columns.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A customer table may contain age, city, purchase amount, and membership status. A tabular tool helps filter, group, clean, and summarize those columns.
Coding example
// Tabular Data Tools
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Create a five-column customer table on paper and list two cleaning tasks you would perform before modelling.
2.10 Visualization Tools
Visualization Tools (tools that turn data into charts so patterns, errors, trends, and unusual values are easier to see). Visual checks often reveal problems that are difficult to notice in raw tables.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A scatter plot can show whether advertising spending tends to rise together with sales, while a box plot can reveal unusual values.
Coding example
// Visualization Tools
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Choose a chart for comparing categories and another chart for studying the relationship between two numerical variables.
2.11 Classical Machine Learning Libraries
Classical Machine Learning Libraries (reusable collections of standard algorithms, preprocessing methods, metrics, and model-selection tools). Libraries save time by providing tested implementations of common methods such as regression, trees, clustering, and evaluation metrics.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
Instead of creating a decision-tree algorithm from the beginning, a learner can use a trusted library implementation and focus on data, settings, and evaluation.
Coding example
// Classical Machine Learning Libraries
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Name three benefits of using a well-tested machine-learning library instead of rebuilding every algorithm from scratch.
2.12 Deep Learning Frameworks
Deep Learning Frameworks (software frameworks that support tensors, neural-network layers, automatic differentiation, training, and accelerated hardware). Deep-learning frameworks make it practical to build and train large neural networks while handling many low-level calculations automatically.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
An image-classification project can define layers, load batches of images, calculate loss, update weights, and use GPU acceleration through a framework.
Coding example
// Deep Learning Frameworks
const relu = x => Math.max(0, x);
const weights = [0.6, -0.2, 0.5];
const input = [2, 1, 3];
const bias = 0.1;
const weightedSum = input.reduce((s,x,i)=>s+x*weights[i], bias);
const output = relu(weightedSum);
console.log({ weightedSum: weightedSum.toFixed(2), output: output.toFixed(2) });Code explanation
- The input vector contains three features and the weight vector assigns one learned importance to each feature.
- The weighted sum combines inputs, weights, and a bias into one number.
- The ReLU activation keeps positive values and replaces negative values with zero.
- This forward calculation is the basic building block that larger neural networks repeat many times.
Expected result: A weighted sum and activated neuron output are printed.
Practice exercise
List the main jobs a deep-learning framework performs during neural-network training.
2.13 CPU vs GPU Computing
CPU vs GPU Computing (comparing general-purpose processors with highly parallel processors used for many numerical operations). CPUs are flexible and suitable for many tasks; GPUs can greatly accelerate workloads that contain many parallel mathematical operations, especially deep learning.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A small tabular model may train quickly on a CPU, while a large image model may benefit significantly from a GPU.
Coding example
// CPU vs GPU Computing
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Give one project that is likely fine on a CPU and one that may benefit from a GPU, and explain why.
2.14 Dependency Management
Dependency Management (tracking the software components and versions a project depends on). Dependency management helps a project remain reproducible and reduces problems caused by incompatible versions.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A team records the exact versions of its data, modelling, and deployment tools so another computer can recreate the same environment later.
Coding example
// Dependency Management
const run = { version: 3, dataVersion: '2026-09', score: 0.91, latencyMs: 42 };
const checks = [
['score', run.score >= 0.85],
['latency', run.latencyMs <= 100]
];
const passed = checks.every(([,ok])=>ok);
console.log({ run, checks, passed });Code explanation
- The `run` object records a few facts that make an experiment or deployment easier to reproduce.
- Each check turns an operational requirement into a simple true/false test.
- `every()` requires all checks to pass before the run is considered acceptable.
- This pattern supports testing, monitoring, release gates, and rollback decisions in production workflows.
Expected result: Run metadata, individual checks, and an overall pass/fail result are printed.
Practice exercise
Explain why recording dependency versions is important when a model must be reproduced months later.
2.15 Creating Your First ML Project
Creating Your First ML Project (organizing a small machine-learning task from problem definition through evaluation). A good first project has a clear target, a manageable dataset, a simple baseline, a meaningful metric, and a short record of what worked and what did not.
For a beginner, focus on the purpose of the concept, the information it uses, and the result you should check. Start with a small example and connect each step to the larger machine-learning workflow before moving to advanced systems.
Example
A beginner project could predict house prices from a small table, compare a simple baseline with one model, and record the evaluation result.
Coding example
// Creating Your First ML Project
const records = [3, 5, 7, 9, 11];
const transform = value => ({ input: value, output: value * 2 + 1 });
const results = records.map(transform);
console.log(results);Code explanation
- The sample starts with a small list of inputs so every result can be checked manually.
- `transform()` represents the main operation for this topic in a deliberately simple form.
- `map()` applies the same rule consistently to every item and returns a new result array.
- Use this pattern to focus on input, transformation, and output before replacing the toy rule with a more advanced method.
Expected result: A transformed result is printed for each input value.
Practice exercise
Choose a simple prediction problem and write its input features, target, evaluation metric, and one possible limitation.
Chapter 2 Review Questions and Answers
Q1. What is Programming Foundations for Machine Learning?
Answer: Programming Foundations for Machine Learning is a way for computers to learn patterns from data instead of receiving every rule by hand. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q2. What is Choosing a Machine Learning Runtime?
Answer: Choosing a Machine Learning Runtime is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q3. What is Virtual Environments?
Answer: Virtual Environments is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q4. What is Notebook Environment Setup?
Answer: Notebook Environment Setup is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q5. What is Notebook Workflow Basics?
Answer: Notebook Workflow Basics is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q6. What is Interactive Lab Workspaces?
Answer: Interactive Lab Workspaces is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q7. What is Development Editor for Machine Learning?
Answer: Development Editor for Machine Learning is a way for computers to learn patterns from data instead of receiving every rule by hand. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q8. What is Numerical Computing Tools?
Answer: Numerical Computing Tools is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q9. What is Tabular Data Tools?
Answer: Tabular Data Tools is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q10. What is Visualization Tools?
Answer: Visualization Tools is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q11. What is Classical Machine Learning Libraries?
Answer: Classical Machine Learning Libraries is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q12. What is Installing Deep Learning Libraries?
Answer: Installing Deep Learning Libraries is machine learning that uses neural networks with many layers. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q13. What is CPU vs GPU Computing?
Answer: CPU vs GPU Computing is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q14. What is Package Management?
Answer: Package Management is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.
Q15. What is Creating Your First ML Project?
Answer: Creating Your First ML Project is a practical concept used within foundations and practical tools. In this chapter, focus on the input, the method or decision, and the result that should be checked.