Exercise 1 — Install the kit

Guided practice10 min
Time
30-40 min
You need
a laptop, an internet connection, Python 3.10 or newer, Git
Deliverable
the output of python data/make_dataset.py and the shape (40, 5) printed by pandas

The lab kit of the course: https://github.com/hrhouma2/aiopsatlas-ml-data-diagnostics-labs-en

Every exercise of the 15 weeks runs inside this kit. You install it once, today. Read this page from top to bottom. If you are on Windows, open Appendix A when a step tells you to. If you are on Linux or macOS, open Appendix B. Never open both.

Goal

NorthPeak Manufacturing gave you one year of sensor readings and incident notes. The data does not exist yet on your laptop. A Python script builds it, always the same way, from a fixed seed. At the end of this exercise you will have: the kit folder, a Python virtual environment with every package of the course, the three clean CSV files, and two local language models.

Setup: the commands (PowerShell, then bash)

Windows, in PowerShell:

powershell
git clone https://github.com/hrhouma2/aiopsatlas-ml-data-diagnostics-labs-en.git
cd aiopsatlas-ml-data-diagnostics-labs-en
py -3.12 -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
python data/make_dataset.py

Linux, macOS, WSL 2 or Git Bash:

bash
git clone https://github.com/hrhouma2/aiopsatlas-ml-data-diagnostics-labs-en.git
cd aiopsatlas-ml-data-diagnostics-labs-en
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python data/make_dataset.py

Then, on every system:

bash
ollama pull llama3.2
ollama pull nomic-embed-text

Expected at the end: machines : 40 rows, readings : 14600 rows, incidents : 155 rows.

The data you will touch

The script data/make_dataset.py writes three clean files in data/clean/. Here is the head of each one, as it looks on our machine.

data/clean/machines.csv, 40 rows, one per machine:

text
machine_id,machine_type,site,install_year,rated_power_kw
M001,pump,Toronto,2022,45.0
M002,pump,Montreal,2016,45.0
M003,pump,Toronto,2013,45.0
M004,pump,Quebec City,2021,45.0
M005,pump,Montreal,2018,45.0
  • machine_id — the code of the machine, M001 to M040.
  • machine_typepump, compressor, conveyor or chiller, 10 of each.
  • siteMontreal, Quebec City or Toronto.
  • install_year — the year the machine was installed, 2012 to 2022.
  • rated_power_kw — the maximum power of the machine, in kilowatts.

data/clean/readings.csv, 14,600 rows, one per machine per day of 2025:

text
reading_id,machine_id,date,load_pct,ambient_c,temperature_c,vibration_mm_s,pressure_bar,power_kw,fault_next_7d
1,M001,2025-01-01,33.9,-3.9,26.1,3.25,6.52,18.3,0
2,M001,2025-01-02,74.3,-3.9,39.6,4.14,6.63,34.3,0
3,M001,2025-01-03,55.7,-4.8,32.8,3.48,7.19,26.0,0
4,M001,2025-01-04,24.0,-6.3,22.0,3.36,6.31,12.9,0
5,M001,2025-01-05,33.1,-6.6,23.6,3.66,5.77,19.5,0
  • load_pct — how hard the machine worked that day, 0 to 100.
  • ambient_c — the outside temperature, in degrees Celsius.
  • temperature_c, vibration_mm_s, pressure_bar, power_kw — the four sensors of the machine.
  • fault_next_7d — 1 if a fault happened in the next seven days, else 0. This is the label.

data/clean/incidents.csv, 155 rows, one per incident:

text
incident_id,machine_id,date,category,severity,downtime_hours,repair_cost_cad,technician,description
INC-0001,M001,2025-02-20,overheating,high,29.9,3465.33,L. Fortin,Overheating alarm on M001. Cooling fan running but airflow blocked by dust.
INC-0002,M001,2025-05-05,bearing_wear,low,2.9,582.47,M. Haddad,Bearing temperature rising on M001. Operator reports a rattling sound near the drive shaft.
  • categorybearing_wear, overheating, leak, electrical or sensor_fault.
  • severitylow, medium or high.
  • description — a short note written by the technician. The text you will read with an LLM later.

Step 1 — Clone the kit

Open a terminal. On Windows, use PowerShell. On Linux or macOS, use the normal terminal. Go to the folder where you keep your courses. Then copy the kit with Git.

bash
git clone https://github.com/hrhouma2/aiopsatlas-ml-data-diagnostics-labs-en.git
cd aiopsatlas-ml-data-diagnostics-labs-en

Look inside. On Windows type dir. On Linux or macOS type ls.

text
data    docs    week01    README.md    requirements.txt

You see data, docs, the kit README.md, requirements.txt, and one weekNN folder per published week. There is no CSV file yet. The data folder only contains make_dataset.py. You will build the data in Step 5.

Step 2 — Check your Python

The kit needs Python 3.10 or newer. Type the command for your system.

Windows:

powershell
py -3.12 --version

Linux or macOS:

bash
python3 --version

Expected, on our machine:

text
Python 3.12.10

If the command is not found, install Python first. Appendix A (Windows) or Appendix B (Linux, macOS) shows how.

Step 3 — Create and activate the virtual environment

A virtual environment is a private folder with its own Python and packages. It keeps the course packages away from the rest of your computer. We call it .venv. You create it once. You activate it every time you open a new terminal.

Windows, in PowerShell:

powershell
py -3.12 -m venv .venv
.\.venv\Scripts\Activate.ps1

Linux or macOS:

bash
python3 -m venv .venv
source .venv/bin/activate

The prompt now starts with (.venv). That is how you know the environment is active. If PowerShell refuses to run the script, go to Appendix A, step A.4.

From now on, python means the Python of .venv. Check it:

bash
python --version
text
Python 3.12.10

Step 4 — Install the packages

The file requirements.txt lists every package of the 15 weeks. Install them all now. The download is about 1 GB. It takes a few minutes.

bash
pip install -r requirements.txt

The last line starts with Successfully installed. Then check the three packages you will use most:

bash
python -c "import pandas, numpy, sklearn; print('pandas', pandas.__version__); print('numpy', numpy.__version__); print('scikit-learn', sklearn.__version__)"

Expected, on our machine:

text
pandas 3.0.5
numpy 2.5.3
scikit-learn 1.9.1

Newer versions are fine. If the import fails, the venv is not active. Go back to Step 3.

Step 5 — Build the dataset

One script builds every file of the course. It uses a fixed seed, 42. Running it twice gives the same bytes. So the numbers in every lesson can be checked on your laptop.

bash
python data/make_dataset.py

Expected output, about 10 seconds:

text
machines   :     40 rows  -> data/clean/machines.csv
readings   :  14600 rows  -> data/clean/readings.csv  (fault_next_7d = 1 on 7.4%)
incidents  :    155 rows  -> data/clean/incidents.csv
raw copies : readings_raw has 14750 rows (150 duplicates), 295 missing temperatures
json/graph/sqlite written.

Read the four lines. 40 machines. 14,600 daily readings, with a fault label on 7.4 % of them. 155 incidents. A dirty copy with 14,750 rows for Week 2. Look inside data now:

text
clean    graph    json    raw    diagnostics.sqlite    make_dataset.py

Step 6 — First look with pandas

pandas is the Python library for tables. You will use it every week. Start Python by typing python in the terminal. Then type these lines one by one.

python
import pandas as pd
machines = pd.read_csv("data/clean/machines.csv")
print(machines.head())
print(machines.shape)
text
  machine_id machine_type         site  install_year  rated_power_kw
0       M001         pump      Toronto          2022            45.0
1       M002         pump     Montreal          2016            45.0
2       M003         pump      Toronto          2013            45.0
3       M004         pump  Quebec City          2021            45.0
4       M005         pump     Montreal          2018            45.0
(40, 5)

head() shows the first five rows. shape gives (rows, columns). Now the two other files:

python
readings = pd.read_csv("data/clean/readings.csv")
print(readings.shape)
print(readings.columns.tolist())
incidents = pd.read_csv("data/clean/incidents.csv")
print(incidents[["incident_id", "machine_id", "date", "category", "severity"]].head(3))
text
(14600, 10)
['reading_id', 'machine_id', 'date', 'load_pct', 'ambient_c', 'temperature_c', 'vibration_mm_s', 'pressure_bar', 'power_kw', 'fault_next_7d']
  incident_id machine_id        date      category severity
0    INC-0001       M001  2025-02-20   overheating   high
1    INC-0002       M001  2025-05-05  bearing_wear    low
2    INC-0003       M001  2025-07-31  bearing_wear    low

One last command. value_counts() counts how many rows have each value.

python
print(machines["machine_type"].value_counts())
text
machine_type
pump          10
compressor    10
conveyor      10
chiller       10
Name: count, dtype: int64

Type exit() to leave Python.

Step 7 — Pull the two local models

The course uses a local language model through Ollama. Install Ollama from ollama.com/download if you have not yet. Then download the two models. The first is 2 GB, the second is 274 MB.

bash
ollama pull llama3.2
ollama pull nomic-embed-text

Check that both are present:

bash
ollama list
text
NAME                       ID              SIZE      MODIFIED
nomic-embed-text:latest    0a109f422b47    274 MB    16 minutes ago
llama3.2:latest            a80c4f17acd5    2.0 GB    17 minutes ago

You will use llama3.2 in Exercise 2, in one hour.

Check yourself

  1. How many rows and columns does machines.csv have?
  2. What does make_dataset.py print for readings?
  3. Which column of readings.csv is the label?
  4. How many machines of each type are there?
Answers
  1. (40, 5): 40 machines, 5 columns.
  2. readings : 14600 rows -> data/clean/readings.csv (fault_next_7d = 1 on 7.4%).
  3. fault_next_7d, the last column.
  4. 10 pumps, 10 compressors, 10 conveyors, 10 chillers.

Bonus (optional)

Run python data/make_dataset.py a second time. Then compare the two versions of machines.csv. On Windows use Get-FileHash data\clean\machines.csv before and after. On Linux or macOS use md5sum data/clean/machines.csv. Are the two hashes the same? Why?

Full solution — Exercise 1 has no script in the kit

This exercise is the setup. There is nothing to save. The full list of commands is in the "Setup" block at the top of the page. The week01/README.md file of the kit lists the scripts of Exercises 2 and 3.

Appendix A — Windows step by step (PowerShell)

Show Appendix A

Read this appendix only if you are on Windows 10 or 11. Every step uses PowerShell, not the old Command Prompt.

A.0 — Install Python and Git

  1. Open python.org/downloads. Download Python 3.12 for Windows.
  2. Run the installer. Tick Add python.exe to PATH. Click Install Now.
  3. Open git-scm.com/download/win. Install Git with the default options.
  4. Close every terminal. Open a new PowerShell window. Type:
powershell
py -3.12 --version
git --version
text
Python 3.12.10
git version 2.49.0.windows.1

Your version numbers may be newer. py is the Windows Python launcher. py -3.12 always picks Python 3.12, even if you have several versions.

A.1 — Choose a short folder

Long paths cause errors on Windows. Keep the kit close to the root of your disk.

powershell
mkdir C:\courses
cd C:\courses

A.2 — Clone the kit

powershell
git clone https://github.com/hrhouma2/aiopsatlas-ml-data-diagnostics-labs-en.git
cd aiopsatlas-ml-data-diagnostics-labs-en
dir

If Git says Filename too long, run this once and clone again:

powershell
git config --global core.longpaths true

A.3 — Create the venv

powershell
py -3.12 -m venv .venv

Nothing is printed. A folder .venv appears.

A.4 — Activate the venv, and the execution policy error

powershell
.\.venv\Scripts\Activate.ps1

The first time, PowerShell often refuses:

text
.\.venv\Scripts\Activate.ps1 : File C:\courses\aiopsatlas-ml-data-diagnostics-labs-en\.venv\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system.

This is a safety setting. Allow local scripts for your user only, then activate again:

powershell
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
.\.venv\Scripts\Activate.ps1

Answer Y if PowerShell asks. The prompt now starts with (.venv).

A.5 — Install the packages

powershell
pip install -r requirements.txt

If pip prints a warning about a new pip version, ignore it. If the install stops with Filename too long or path too long, go back to A.1 and A.2.

A.6 — Build the dataset and look at it

powershell
python data/make_dataset.py
Get-Content data\clean\machines.csv -TotalCount 3
text
machine_id,machine_type,site,install_year,rated_power_kw
M001,pump,Toronto,2022,45.0
M002,pump,Montreal,2016,45.0

A.7 — Install Ollama

Download the Windows installer from ollama.com/download. Run it. Ollama starts in the background and shows an icon in the system tray. Then, in PowerShell:

powershell
ollama pull llama3.2
ollama pull nomic-embed-text
ollama list

A.8 — Next time you open PowerShell

powershell
cd C:\courses\aiopsatlas-ml-data-diagnostics-labs-en
.\.venv\Scripts\Activate.ps1

That is all. The packages and the data stay on disk.

Appendix B — Linux and macOS step by step

Show Appendix B

Read this appendix only if you are on Linux, macOS, WSL 2 or Git Bash. Every step uses the normal terminal.

B.0 — Install Python and Git

Ubuntu or Debian:

bash
sudo apt update
sudo apt install -y python3 python3-venv python3-pip git

Fedora:

bash
sudo dnf install -y python3 git

macOS, with Homebrew:

bash
brew install python@3.12 git

Check:

bash
python3 --version
git --version
text
Python 3.12.10
git version 2.49.0

Your version numbers will differ. Anything from Python 3.10 works.

B.1 — Choose a folder

bash
mkdir -p ~/courses
cd ~/courses

B.2 — Clone the kit

bash
git clone https://github.com/hrhouma2/aiopsatlas-ml-data-diagnostics-labs-en.git
cd aiopsatlas-ml-data-diagnostics-labs-en
ls
text
data  docs  week01  README.md  requirements.txt

B.3 — Create the venv

bash
python3 -m venv .venv

On Ubuntu, if this fails with ensurepip is not available, install python3-venv (see B.0) and run it again.

B.4 — Activate the venv

bash
source .venv/bin/activate

The prompt now starts with (.venv). Inside the venv, python and pip point to the venv.

B.5 — Install the packages

bash
pip install -r requirements.txt

On a Mac with Apple Silicon, some packages compile for a minute. That is normal.

B.6 — Build the dataset and look at it

bash
python data/make_dataset.py
head -n 3 data/clean/machines.csv
text
machine_id,machine_type,site,install_year,rated_power_kw
M001,pump,Toronto,2022,45.0
M002,pump,Montreal,2016,45.0

B.7 — Install Ollama

Linux:

bash
curl -fsSL https://ollama.com/install.sh | sh

macOS: download the app from ollama.com/download and open it once. Then, on both systems:

bash
ollama pull llama3.2
ollama pull nomic-embed-text
ollama list

On Linux, if ollama pull says the server is not running, start it in a second terminal with ollama serve.

B.8 — Next time you open a terminal

bash
cd ~/courses/aiopsatlas-ml-data-diagnostics-labs-en
source .venv/bin/activate
Stuck? Common errors

All systems — ModuleNotFoundError: No module named 'pandas'. The venv is not active, or you used the wrong Python. Look for (.venv) at the start of the prompt. Activate again (Step 3).

All systems — FileNotFoundError: data/clean/machines.csv. You are not in the kit folder, or you did not run make_dataset.py. Type cd aiopsatlas-ml-data-diagnostics-labs-en, then Step 5.

All systems — python: command not found inside the venv. On some Linux systems the venv only creates python3. Use python3 instead. Inside the venv, both point to the same file.

Windows only — running scripts is disabled on this system. See A.4: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned.

Windows only — python opens the Microsoft Store. Windows has a fake python alias. Use py -3.12 to create the venv. Once the venv is active, python is the right one.

Windows only — Filename too long during git clone or pip install. Move to a short folder like C:\courses and run git config --global core.longpaths true.

Linux only — The virtual environment was not created successfully because ensurepip is not available. Run sudo apt install python3-venv, delete the .venv folder, and create it again.

macOS and bash — pip: command not found. Use python3 -m pip install -r requirements.txt.

All systems — ollama: command not found. Ollama is not installed, or the terminal was open before the install. Close the terminal, open a new one, try again.