# Set up for Unit 17: data science tools

> Add numpy, pandas, scikit-learn and matplotlib to your course folder, run notebooks in VS Code, and prove it works. About 30 minutes, free, no new accounts.

- Course: Orchestrate, Unit 17 · Machine learning fundamentals
- Page: https://erpfde.com/topics/set-up-for-unit-17/
- Updated: 2026-11-26
- Reading time: Foundational 5 min, Deep 30 min

Independent learning resource. Not affiliated with, sponsored by or endorsed by SAP SE. SAP and other SAP products mentioned are trademarks of SAP SE in Germany and other countries.

## Foundational layer

### The 60-second version

Unit 17 teaches how machines learn from examples. To try that, learners need four standard Python libraries for working with data and one way to run code in small pieces and see the result straight away.

The libraries are **numpy** (fast arithmetic on long lists of numbers), **pandas** (tables, like a spreadsheet you drive with code), **scikit-learn** (ready-made machine learning methods) and **matplotlib** (charts). The "small pieces" tool is a **notebook**: a file that mixes code, results and charts on one page. VS Code, which learners installed in Unit 2, opens notebooks with one free extension.

Setup takes about 30 minutes. It costs nothing and needs no new accounts. All data in Unit 17 is made up to look like SAP data, so nothing leaves the learner's laptop.

### Why it matters to the business

These four libraries are the common language of data work. Data scientists at your company, at SAP partners and at SAP itself use them to explore data before any model reaches production. When a team says "we looked at the data in a notebook", this is what they mean.

For a leader, two things follow:

- **Notebooks are for exploring, not for running the business.** A notebook that predicts late deliveries is a good way to test an idea. It is not a system anyone should rely on at month-end. Moving from notebook to production is covered in later units.
- **Notebooks keep their results inside the file.** A table printed in a notebook is saved in it. If someone opens real customer data in a notebook and shares the file, the data goes with it. The course uses made-up data for exactly this reason.

### How SAP does it

SAP's data scientists use the same open tools, and SAP also offers its own Python library, **hana-ml**, for machine learning inside SAP HANA. As of September 2026 it is published on PyPI and works with pandas tables, so skills from this unit carry over. It needs access to an SAP HANA Cloud system, which this unit doesn't. The deep layer explains the difference.

### What this unit adds

| Item | What it is | Cost | Used in |
| --- | --- | --- | --- |
| numpy | Fast maths on arrays of numbers | Free | Every Unit 17 topic, and most later ones |
| pandas | Tables of data: load, filter, group, join | Free | [Machine learning in plain terms](https://erpfde.com/topics/machine-learning-in-plain-terms/), [predicting late deliveries](https://erpfde.com/topics/predicting-late-deliveries-with-sap-data/) |
| scikit-learn | Ready-made models and metrics | Free | [Classification and the metrics that matter](https://erpfde.com/topics/classification-and-the-metrics-that-matter/), predicting late deliveries |
| matplotlib | Charts | Free | [Gradient descent by hand](https://erpfde.com/topics/gradient-descent-by-hand/), classification metrics |
| ipykernel | Lets VS Code run notebook code with your course Python | Free | All notebooks from now on |
| Jupyter extension for VS Code | Opens and runs notebooks in the editor | Free | All notebooks from now on |

No SAP system, cloud account or model key is needed for this unit.

### Time and money

- **Time:** about 30 minutes, most of it waiting for downloads. The libraries are a few hundred megabytes in total.
- **Money:** nothing.
- **One version rule:** as of September 2026, the latest releases of these libraries need Python 3.11 or newer, and numpy's newest release needs 3.12. A learner who installed Python in Unit 2 already meets this.

### Questions to ask IT

- Can learners install Python packages from PyPI (`pypi.org` and `files.pythonhosted.org`), or do we have an internal package mirror to use instead?
- Can learners install VS Code extensions from the Marketplace, or is the list controlled?
- What is our rule for opening company data in notebooks on laptops, and for sharing notebook files?
- If a learner later wants to try SAP's own Python library for machine learning inside SAP HANA, who can give access to a HANA Cloud system for learning?

### Common misconceptions

- **"We need Anaconda or a data science platform."** Not for this course. Plain Python with a virtual environment and `pip` is enough, and it is the same setup learners already have.
- **"Notebooks are a separate program."** VS Code opens them directly with the Jupyter extension. No browser tool is needed.
- **"Machine learning needs a GPU."** Not for Unit 17. These models train in seconds on any laptop.
- **"A good notebook result means the model is ready."** It means the idea is worth testing further. Unit 7 covers how to evaluate properly.

### Key terms

- **Library (package):** ready-made code you install with `pip`.
- **DataFrame:** a pandas table with named columns, the main thing you work with in Unit 17.
- **Notebook (`.ipynb` file):** a page of code cells, each followed by its output.
- **Cell:** one block of code in a notebook, run on its own.
- **Kernel:** the running Python behind a notebook. It remembers what earlier cells did.

### Check yourself

1. What does Unit 17 add to a learner's laptop, and what does it cost?
   - A. A paid data science platform and a GPU, plus a new cloud account
   - B. An SAP HANA Cloud system for hana-ml, and access set up by IT
   - C. Four free data libraries and notebook support; 30 minutes, no cost
   - D. A new AI model account and key, plus Anaconda for the data libraries

   Answer: C. Four free Python libraries for data work (numpy, pandas, scikit-learn and matplotlib), plus `ipykernel` and VS Code's Jupyter extension to run notebooks. About 30 minutes, no cost and no new accounts.

2. What is a notebook, and what is it good for?
   - A. A production tool for running scheduled business jobs at month-end
   - B. A page of code cells and their outputs, for exploring data and ideas
   - C. A written log of what the learner did, kept for later review and audit
   - D. A database that stores SAP data so several learners can share it

   Answer: B. A page of code cells, each followed by its output, where Python stays running between cells. It is good for exploring data and testing an idea, not for running a business process that people rely on.

3. Why is sharing a notebook a data-protection risk?
   - A. Outputs are saved inside the file, so any data shown travels with it
   - B. Notebooks upload their data to the editor's vendor every time they run
   - C. Notebooks can't be opened on other computers without the same data
   - D. Sharing a notebook breaks the virtual environment on the other laptop

   Answer: A. Notebooks save their results inside the file. If someone opens real customer data and shares or commits the notebook, the data goes with it. The course uses made-up data for exactly this reason.

4. Does Unit 17 need a GPU, Anaconda or a data science platform?
   - A. Yes; a GPU is required for any machine learning, even small models
   - B. Yes; pandas only works inside a special data science distribution
   - C. Only on Windows laptops; macOS and Linux can use plain Python
   - D. No; plain Python and `pip` are enough, and models train in seconds

   Answer: D. No. Plain Python with the course's virtual environment and `pip` is enough, and the Unit 17 models train in seconds on any laptop.

5. A team shows a good result from a notebook. Is the model ready for production?
   - A. Yes, if the accuracy shown in the notebook is above 90%
   - B. Yes, once the notebook is saved and committed in Git
   - C. No; it means the idea is worth testing further
   - D. Yes, if a data scientist wrote and ran it

   Answer: C. No. A good notebook result means the idea is worth testing further. Proper evaluation comes in Unit 7, and moving from notebook to production in later units.

6. What should you ask IT before learners start Unit 17?
   - A. Whether learners can get admin access to SAP production to pull real customer data
   - B. Whether PyPI and Marketplace installs are allowed, and the rule on data in notebooks
   - C. Whether IT can build and maintain the notebooks for every learner
   - D. Whether learners may use personal model keys and cloud accounts at work

   Answer: B. Whether learners can install packages from PyPI or must use an internal mirror, whether VS Code extensions are allowed, and what the rule is for opening company data in notebooks and sharing notebook files.

7. How do these open tools connect to SAP?
   - A. SAP uses the same tools, and its hana-ml library works with pandas tables
   - B. They don't connect; SAP supports only its own languages and tools
   - C. SAP has replaced pandas with hana-ml, so pandas skills don't carry over
   - D. SAP requires every notebook to run inside an S/4HANA system

   Answer: A. SAP's data scientists use the same tools, and SAP publishes hana-ml, a Python library that works with pandas-style tables and runs machine learning inside SAP HANA. It isn't needed for Unit 17, but the skills carry over.

## Deep layer

### Mental model: same folder, same Python, a new way to run it

Nothing about your course folder changes. You still have one `.venv`, one `requirements.txt` and one Git repository. This unit adds five lines to `requirements.txt` and one new way to run code: a notebook, where Python stays running between cells.

```mermaid
flowchart LR
  R[requirements.txt<br/>+5 lines] -->|pip install| V[.venv<br/>course Python]
  V -->|runs| S[hello_data.py<br/>in the terminal]
  V -->|kernel via ipykernel| N[first_notebook.ipynb<br/>in VS Code]
  S -->|writes| D[sample_deliveries.csv]
  D -->|read by| N
```

A script runs top to bottom and exits. A notebook's kernel stays alive, so a variable you made in cell 1 is still there in cell 5. That is why notebooks are good for exploring data, and also why they confuse people: the result depends on which cells you ran and in what order.

### How it works

When you open a notebook in VS Code, the Jupyter extension starts a **kernel**: a Python process that waits for code. You choose which Python it uses with the **Select Kernel** button. If you pick your course `.venv`, the kernel sees every library you installed there.

VS Code's documentation is clear on what the environment needs: not the full Jupyter package, only `ipykernel`, the small library that lets a Python environment act as a kernel. That is why `ipykernel` is in this unit's list.

The four data libraries build on each other:

| Library | Builds on | What you do with it in Unit 17 |
| --- | --- | --- |
| numpy | Nothing (compiled code) | Make random sample data, do arithmetic on whole columns |
| pandas | numpy | Hold deliveries in a table, group by plant, read and write CSV |
| scikit-learn | numpy and SciPy | Split data, train a model, score it |
| matplotlib | numpy | Draw charts in scripts and notebooks |

`pip` installs the extra libraries each one depends on, such as SciPy for scikit-learn, without you asking.

> **Note** Words you will meet. **Array**: a list of numbers numpy can work on in one go. **CSV**: a plain text table, one row per line, values separated by commas; Excel opens it. **Kernel**: the Python process behind a notebook. **Seed**: a starting number for random data, so you get the same "random" data every run.

### Build it yourself: add the data tools and prove they work

You will add the Unit 17 libraries to your course folder, run a short script that makes SAP-shaped sample deliveries and trains a first model, then open the same data in a notebook. Finally, a check script confirms everything.

**Before you start:** complete [Set up your computer for this course](https://erpfde.com/topics/set-up-your-computer/). It installs Python, VS Code and Git, and creates your `orchestrate-course` folder with its `.venv` virtual environment and `requirements.txt`. This walkthrough doesn't repeat those steps.

#### What you need

- Your course folder from Unit 2.
- About 30 minutes and an internet connection.
- No accounts and no cost.

#### Step 1: Check your Python version

1. Open VS Code, choose **File > Open Folder**, and open `orchestrate-course`.
2. Open a terminal: **Terminal > New Terminal**.
3. Run:

   ```bash
   python --version
   ```

   (On macOS or Linux, before `.venv` is active, use `python3`.)
4. You need **3.11 or newer**. The versions pinned in Step 3 were tested on Python 3.11 and 3.13 on 7 November 2026. numpy 2.4.6 is pinned rather than the newest numpy because numpy's newest releases need Python 3.12.

If you see 3.10 or older, install a newer Python (Unit 2, Step 1), then delete the `.venv` folder in VS Code's file list and recreate it:

- **Windows (PowerShell):**

  ```powershell
  python -m venv .venv
  .venv\Scripts\Activate.ps1
  pip install -r requirements.txt
  ```

- **macOS / Linux:**

  ```bash
  python3 -m venv .venv
  source .venv/bin/activate
  pip install -r requirements.txt
  ```

#### Step 2: Turn on the virtual environment

If your prompt doesn't start with `(.venv)`, turn it on:

- **Windows (PowerShell):**

  ```powershell
  .venv\Scripts\Activate.ps1
  ```

- **macOS / Linux:**

  ```bash
  source .venv/bin/activate
  ```

#### Step 3: Add the Unit 17 libraries

1. In VS Code, open `requirements.txt` and add these five lines below the existing ones:

   ```text
   numpy==2.4.6
   pandas==3.0.6
   scikit-learn==1.9.1
   matplotlib==3.11.2
   ipykernel==7.4.0
   ```

   The `==` pins an exact version, so your results match this topic's. These are the versions tested on 7 November 2026.

2. Save the file (Ctrl+S, or Cmd+S on Mac).
3. With `(.venv)` showing, run:

   ```bash
   pip install -r requirements.txt
   ```

4. Wait for a line starting `Successfully installed`. This can take a few minutes; the libraries are large. Libraries you already had show `Requirement already satisfied`, which is fine.

> **Tip** The name you install and the name you import are not always the same. You install `scikit-learn` but write `import sklearn` in code.

#### Step 4: Add the Jupyter extension to VS Code

1. Click the **Extensions** icon on the left (four small squares).
2. Search for **Jupyter** and install the one published by **Microsoft**.
3. If VS Code asks to reload, click the button it shows.

#### Step 5: Make the Unit 17 folder

In the terminal, from your course folder:

- **Windows (PowerShell):**

  ```powershell
  New-Item -ItemType Directory -Force unit17
  cd unit17
  ```

- **macOS / Linux:**

  ```bash
  mkdir -p unit17
  cd unit17
  ```

#### Step 6: Run the smoke-test script

This script proves all four libraries work together. It makes 500 made-up outbound deliveries with fields shaped like SAP data (a delivery number, a plant, a shipping type, items, weight, lead time) and a `Late` flag. Then it prints a summary, draws one chart and trains a first model. Unit 17's later topics explain what the model is doing; here it only needs to run.

1. In VS Code's file list, right-click `unit17`, choose **New File** and name it `hello_data.py`.
2. Paste the code below and save.
3. In the terminal, still inside `unit17`, run:

   ```bash
   python hello_data.py
   ```

```python
"""Unit 17 smoke test: make SAP-shaped sample deliveries, look at them, fit a tiny model.

How to run (from the unit17 folder, with the course .venv turned on):
    python hello_data.py            # 500 made-up deliveries
    python hello_data.py --rows 2000

All data is made up. It writes sample_deliveries.csv and late_by_plant.png next to this file.
"""
import argparse
from pathlib import Path

import matplotlib

matplotlib.use("Agg")  # draw into a file, no window needed
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

HERE = Path(__file__).parent
PLANTS = ["1010", "1020", "1710"]           # made-up plant codes
CARRIERS = ["ROAD", "RAIL", "EXPRESS"]      # made-up shipping types


def make_deliveries(rows: int, seed: int = 42) -> pd.DataFrame:
    """Build a table that looks like outbound deliveries, with a 'late' flag."""
    rng = np.random.default_rng(seed)  # same seed, same data, every run
    df = pd.DataFrame({
        "Delivery": [str(80000000 + i) for i in range(rows)],
        "Plant": rng.choice(PLANTS, size=rows),
        "ShippingType": rng.choice(CARRIERS, size=rows, p=[0.6, 0.3, 0.1]),
        "Items": rng.integers(1, 12, size=rows),
        "WeightKg": rng.gamma(2.0, 150.0, size=rows).round(1),
        "LeadTimeDays": rng.integers(1, 15, size=rows),
    })
    # A made-up rule plus noise decides which deliveries were late.
    risk = (
        0.25 * df["Items"]
        + 0.004 * df["WeightKg"]
        - 0.35 * df["LeadTimeDays"]
        + np.where(df["Plant"] == "1710", 1.0, 0.0)
        + np.where(df["ShippingType"] == "EXPRESS", -1.5, 0.0)
        + rng.normal(0, 1.0, size=rows)
    )
    df["Late"] = (risk > 0).astype(int)
    return df


def main() -> None:
    parser = argparse.ArgumentParser(description="Unit 17 smoke test on made-up deliveries.")
    parser.add_argument("--rows", type=int, default=500, help="how many deliveries to make")
    args = parser.parse_args()

    # 1. numpy + pandas: make and inspect the data
    df = make_deliveries(args.rows)
    df.to_csv(HERE / "sample_deliveries.csv", index=False)
    print(f"Made {len(df)} deliveries. First three:")
    print(df.head(3).to_string(index=False))
    print("\nShare of late deliveries by plant:")
    by_plant = df.groupby("Plant")["Late"].mean().round(2)
    print(by_plant.to_string())

    # 2. matplotlib: one chart, saved as a file
    ax = by_plant.plot(kind="bar", color="#4a6fa5", rot=0)
    ax.set_title("Share of late deliveries by plant (made-up data)")
    ax.set_ylabel("share late")
    plt.tight_layout()
    plt.savefig(HERE / "late_by_plant.png")
    plt.close()

    # 3. scikit-learn: a first model, just to prove the library works
    features = pd.get_dummies(df[["Items", "WeightKg", "LeadTimeDays", "Plant", "ShippingType"]])
    x_train, x_test, y_train, y_test = train_test_split(
        features, df["Late"], test_size=0.25, random_state=0
    )
    model = LogisticRegression(max_iter=1000).fit(x_train, y_train)
    accuracy = model.score(x_test, y_test)
    print(f"\nModel accuracy on deliveries it has not seen: {accuracy:.2f}")
    print("Wrote sample_deliveries.csv and late_by_plant.png")


if __name__ == "__main__":
    main()
```

**What success looks like:**

```text
Made 500 deliveries. First three:
Delivery Plant ShippingType  Items  WeightKg  LeadTimeDays  Late
80000000  1010         RAIL      6     132.1             3     1
80000001  1710         RAIL      3     256.8             1     1
80000002  1020         ROAD      3     230.0             9     0

Share of late deliveries by plant:
Plant
1010    0.46
1020    0.53
1710    0.63

Model accuracy on deliveries it has not seen: 0.85
Wrote sample_deliveries.csv and late_by_plant.png
```

Your numbers should match, because the seed (42 for the data, 0 for the split) fixes the random data and the pinned versions fix the libraries. If you install other versions, the last decimal of the accuracy may differ.

> **Note** The deliveries, late shares and the 0.85 accuracy come from made-up data generated by the script. They show that the tools work, not how well a model predicts late deliveries in a real SAP system. Two new files appear in `unit17`. Click `late_by_plant.png` to see the chart.

**What each part of the script does:**

| Part | What it does |
| --- | --- |
| `matplotlib.use("Agg")` | Draws charts into files, so the script needs no window |
| `make_deliveries` | Uses numpy's random generator with a fixed seed to build a pandas table of made-up deliveries, then marks some late with a made-up rule plus noise |
| `df.to_csv(...)` | Saves the table as `sample_deliveries.csv` for the notebook in Step 7 |
| `groupby("Plant")["Late"].mean()` | Share of late deliveries per plant, the kind of question you ask first |
| `by_plant.plot(...)`, `savefig` | Turns that summary into a bar chart file |
| `pd.get_dummies` | Turns text columns such as `Plant` into 0/1 columns a model can use |
| `train_test_split`, `LogisticRegression`, `score` | Holds back a quarter of the rows, trains on the rest, and reports how often the model is right on the held-back rows |
| `--rows` | Optional: make more or fewer deliveries, for example `--rows 2000` |

#### Step 7: Open the data in a notebook

1. Press Ctrl+Shift+P (Cmd+Shift+P on Mac) and run **Create: New Jupyter Notebook**.
2. Save it straight away (Ctrl+S or Cmd+S) as `first_notebook.ipynb` inside `unit17`.
3. Click **Select Kernel** at the top right of the notebook. Choose **Python Environments**, then the environment inside your course folder's `.venv`.
4. In the first cell, paste the code below. Run it with **Shift+Enter**, which runs the cell and moves to a new one.

   ```python
   import pandas as pd

   df = pd.read_csv("sample_deliveries.csv", dtype={"Delivery": str, "Plant": str})
   df.head()
   ```

   You see a table of the first five deliveries under the cell.
5. In the next cell, paste and run:

   ```python
   df.groupby("Plant")["Late"].mean().plot(kind="bar", rot=0, title="Share late by plant")
   ```

   A bar chart appears under the cell.
6. In a third cell, paste and run:

   ```python
   df.groupby("ShippingType")["Late"].mean().round(2)
   ```

   ```text
   ShippingType
   EXPRESS    0.31
   RAIL       0.59
   ROAD       0.55
   Name: Late, dtype: float64
   ```

7. Click the **Variables** icon in the notebook toolbar. A panel opens listing `df`. Use **Show variable in data viewer** next to it to scroll through all 500 rows.
8. Save the notebook.

> **Note** `dtype={"Delivery": str, "Plant": str}` tells pandas to keep these columns as text. Without it, pandas reads `1010` as a number. SAP keys such as plants and document numbers are codes, not quantities, and some have leading zeros that a number would lose.

> **Tip** If the notebook says it can't find `sample_deliveries.csv`, the notebook isn't saved in `unit17`, or you skipped Step 6. Save it in `unit17` and run Step 6 first.

#### Step 8: Run the Unit 17 check

1. Go back to your course folder in the terminal:

   ```bash
   cd ..
   ```

2. In VS Code, create a new file in the course folder (not in `unit17`), paste the script below and save it as `check_unit17.py`.
3. Run it:

   ```bash
   python check_unit17.py
   ```

```python
"""Check that your computer is ready for Unit 17 (data science tools).

Run it from your course folder:  python check_unit17.py
It only reads your setup; it installs nothing and sends nothing anywhere.
"""
import importlib.metadata
import importlib.util
import os
import shutil
import subprocess
import sys

problems = 0


def report(ok: bool, label: str, fix: str = "", optional: bool = False) -> None:
    """Print one line: OK, MISSING (must fix) or LATER (optional for now)."""
    global problems
    if ok:
        print(f"  OK       {label}")
    elif optional:
        print(f"  LATER    {label}  ->  {fix}")
    else:
        problems += 1
        print(f"  MISSING  {label}  ->  {fix}")


def version_of(package: str) -> str:
    try:
        return importlib.metadata.version(package)
    except importlib.metadata.PackageNotFoundError:
        return ""


print("\n1. Python")
v = sys.version_info
report(v >= (3, 11), f"Python {v.major}.{v.minor}.{v.micro}",
       "Unit 17 libraries need Python 3.11 or newer; install a newer Python and recreate .venv (Step 1)")
report(sys.prefix != sys.base_prefix, "virtual environment is active", "activate .venv (Step 2)")

print("\n2. Libraries")
LIBRARIES = [  # (import name, package name on PyPI)
    ("numpy", "numpy"),
    ("pandas", "pandas"),
    ("sklearn", "scikit-learn"),
    ("matplotlib", "matplotlib"),
    ("ipykernel", "ipykernel"),
]
for module, package in LIBRARIES:
    found = importlib.util.find_spec(module) is not None
    label = f"{package} {version_of(package)}".strip()
    report(found, label, "pip install -r requirements.txt (Step 3)")

print("\n3. Libraries work together")
# Import all of them in a fresh Python and do one tiny calculation each.
# This catches broken or half-finished installs that find_spec can't see.
test = (
    "import matplotlib; matplotlib.use('Agg'); import matplotlib.pyplot as plt;"
    "import numpy as np, pandas as pd;"
    "from sklearn.linear_model import LinearRegression;"
    "df = pd.DataFrame({'x': np.arange(5), 'y': np.arange(5) * 2.0});"
    "m = LinearRegression().fit(df[['x']], df['y']);"
    "assert abs(m.coef_[0] - 2.0) < 1e-6;"
    "plt.plot(df['x'], df['y']); plt.close()"
)
try:
    result = subprocess.run([sys.executable, "-c", test], capture_output=True, text=True, timeout=180)
    ok = result.returncode == 0
    detail = (result.stderr.strip().splitlines() or ["unknown error"])[-1] if not ok else ""
except subprocess.TimeoutExpired:
    ok, detail = False, "timed out"
report(ok, "import, fit a line, draw a chart",
       f"{detail}; reinstall with pip install --force-reinstall -r requirements.txt (Step 3)")

print("\n4. Editor")
code = shutil.which("code")
if code:
    try:
        exts = subprocess.run([code, "--list-extensions"], capture_output=True, text=True, timeout=60).stdout.lower()
    except Exception:
        exts = ""
    report("ms-toolsai.jupyter" in exts, "VS Code Jupyter extension",
           "install Jupyter by Microsoft in VS Code (Step 4)", optional=True)
else:
    report(False, "VS Code 'code' command", "can't check from here; confirm Step 4 in VS Code by eye", optional=True)

print("\n5. Course folder")
report(os.path.isdir("unit17"), "unit17 folder", "create it (Step 5)", optional=True)
report(os.path.exists(os.path.join("unit17", "hello_data.py")), "unit17/hello_data.py",
       "create it (Step 6)", optional=True)

print()
if problems:
    print(f"{problems} item(s) to fix. Fix them in order, then run this again.")
    sys.exit(1)
print("All set. Your computer is ready for Unit 17.")
```

**What success looks like:**

```text
1. Python
  OK       Python 3.11.15
  OK       virtual environment is active

2. Libraries
  OK       numpy 2.4.6
  OK       pandas 3.0.6
  OK       scikit-learn 1.9.1
  OK       matplotlib 3.11.2
  OK       ipykernel 7.4.0

3. Libraries work together
  OK       import, fit a line, draw a chart

4. Editor
  LATER    VS Code 'code' command  ->  can't check from here; confirm Step 4 in VS Code by eye

5. Course folder
  OK       unit17 folder
  OK       unit17/hello_data.py

All set. Your computer is ready for Unit 17.
```

This run used Python 3.11; on a newer Python the first line shows that version. The library versions match the pins from Step 3. If you installed other versions, that is fine as long as each line says `OK`. The `LATER` line under **Editor** is also fine: it means the script couldn't ask VS Code directly because the `code` command isn't on your PATH, which is common on macOS. Step 7 working already proves the extension is there. If `code` is on your PATH, you see `OK       VS Code Jupyter extension` instead.

**What each part of the check does:**

| Part | What it checks |
| --- | --- |
| Python | Version 3.11 or newer, and that `.venv` is active |
| Libraries | That each library can be found, and which version is installed |
| Libraries work together | Starts a fresh Python, imports all four, fits a straight line and draws a chart. This catches broken installs a simple "is it there?" test misses |
| Editor | Asks VS Code, through its `code` command, whether the Jupyter extension is installed |
| Course folder | That `unit17` and `hello_data.py` exist |

Like `check_setup.py`, it uses only Python's built-in modules, so it runs even before Step 3. It changes nothing and sends nothing anywhere.

#### Step 9: Save your work in Git

1. Tell Git to ignore notebook scratch files. Open `.gitignore` in your course folder and add this line:

   ```text
   .ipynb_checkpoints/
   ```

2. Save everything with Git, from the course folder:

   ```bash
   git add requirements.txt .gitignore check_unit17.py unit17/hello_data.py unit17/first_notebook.ipynb
   git commit -m "Set up Unit 17 data tools"
   ```

The CSV and PNG are left out on purpose: the script recreates them in a second.

#### If something goes wrong

| What you see | What it means | What to do |
| --- | --- | --- |
| `python` is not recognized, or `command not found` | Python isn't installed, or the terminal can't find it | Windows: repeat Unit 2, Step 1, then open a new terminal. macOS/Linux: use `python3` until `.venv` is active |
| `MISSING Python 3.10...` or pip says `No matching distribution found for pandas` | Your Python is too old for current releases | Install a newer Python and recreate `.venv` (Step 1) |
| `ModuleNotFoundError: No module named 'sklearn'` (or `pandas`, `numpy`) | The library isn't installed in the Python you're using | Check for `(.venv)` in the prompt, then repeat Step 3.3 |
| `MISSING import, fit a line, draw a chart` with an error name | A library is only half installed, often after a dropped download | Run `pip install --force-reinstall -r requirements.txt` |
| pip shows `ProxyError`, `SSLError` or `Could not fetch URL` | Your network or company proxy blocks PyPI | Try a home network, or ask IT for access to `pypi.org` and `files.pythonhosted.org`, or for the internal package mirror |
| No `.venv` in the notebook's kernel list | VS Code hasn't found the environment, or `ipykernel` isn't in it | Finish Step 3, then close and reopen the course folder in VS Code and try **Select Kernel** again |
| Notebook cell fails with `No module named 'pandas'` though the check says OK | The notebook uses a different Python | Click the kernel name at the top right and choose the `.venv` one (Step 7.3) |
| Notebook can't find `sample_deliveries.csv` | The notebook isn't in `unit17`, or Step 6 wasn't run | Save the notebook in `unit17` and run `python hello_data.py` there |
| Script runs but no chart file appears | You ran it from another folder and are looking in the wrong place | The script writes next to itself, in `unit17`. Look there |
| Windows: `.venv\Scripts\Activate.ps1 cannot be loaded` | PowerShell blocks scripts | Run `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`, answer `Y`, and try again |

### Where this shows up in SAP

pandas DataFrames are also the meeting point with SAP's own Python tools. SAP publishes **hana-ml**, the Python machine learning client for SAP HANA, on PyPI. As described there in September 2026, it gives you a HANA DataFrame that queries data without copying it to your laptop, plus Python access to two in-database libraries: the Predictive Analysis Library (PAL) for classic algorithms and the Automated Predictive Library (APL) for automated modelling. It can turn a HANA DataFrame into a pandas DataFrame and back.

The difference matters. In this unit, data comes to the model on your laptop. With hana-ml, the model runs inside the database, next to the data. That is often the right choice for large SAP tables and for data that must not leave the system.

hana-ml is **not needed for Unit 17**. It needs an SAP HANA Cloud instance with the script server, PAL and APL enabled, according to SAP Learning's setup lesson (written for an earlier hana-ml release), and it is licensed under the SAP Developer License Agreement. SAP Learning has a learning journey, "Developing AI workflows with the Python Machine Learning Client for SAP HANA", for when you have access. The concepts you learn in Unit 17 with scikit-learn (training, test splits, metrics) carry over directly.

### Pitfalls

- **Running cells out of order.** A notebook remembers everything. If a result looks wrong, restart the kernel from the notebook toolbar and run all cells from the top.
- **The wrong kernel.** The kernel name shows at the top right. If it isn't your `.venv`, imports fail or use other library versions.
- **Codes read as numbers.** Plants, company codes and document numbers are text. Set `dtype` when reading CSV files, or leading zeros disappear.
- **Real data in notebooks.** Outputs are saved inside the `.ipynb` file. Opening real customer data and committing the notebook puts that data in your Git history. Use sample data, and clear all outputs (from the notebook toolbar) before sharing.
- **Installing "just one more library" outside `.venv`.** Always check for `(.venv)` before `pip install`, and add the library to `requirements.txt` so the setup can be rebuilt.

### Exercise: make the sample data yours

The next topics use `sample_deliveries.csv`. Make a version that fits the business you know.

1. Copy `hello_data.py` to `my_deliveries.py` in `unit17`.
2. In `make_deliveries`, add a column `Customer` with three made-up customer numbers, chosen at random like `Plant` is.
3. Add one line to the `risk` calculation so deliveries to one of those customers are more often late.
4. Change the output file names to `my_deliveries.csv` and `my_late_by_plant.png`.
5. Run `python my_deliveries.py`. Check that the new CSV has a `Customer` column.
6. In `first_notebook.ipynb`, add a cell that reads `my_deliveries.csv` and shows the share of late deliveries by `Customer`. Check that your chosen customer has the highest share.
7. Save your work in Git:

   ```bash
   git add unit17/my_deliveries.py unit17/first_notebook.ipynb
   git commit -m "Add my own sample deliveries"
   ```

**Done when:** `check_unit17.py` prints `All set`, `my_deliveries.csv` has a `Customer` column, the notebook shows your chosen customer as the most often late, and `git log` shows the commit. Keep the script: Unit 17's [late-delivery prediction topic](https://erpfde.com/topics/predicting-late-deliveries-with-sap-data/) trains on data like this.

### Check yourself

1. Which package name do you install, and which name do you import, for scikit-learn?
   - A. Install `sklearn`, import `scikit-learn`
   - B. Install and import `scikit-learn`
   - C. Install and import `sklearn`
   - D. Install `scikit-learn`, import `sklearn`

   Answer: D. You install `scikit-learn` and write `import sklearn`. Install names and import names don't always match.

2. What does a notebook's kernel remember between cells, and how can that give you a wrong result?
   - A. Nothing; each cell starts a fresh Python, so order never matters
   - B. Only the last cell's output, so earlier variables must be re-created
   - C. Every variable from cells already run, so run order can change results
   - D. The file's whole Git history, so old versions can leak into results

   Answer: C. Every variable and import from cells already run. Results then depend on which cells ran and in what order. If something looks wrong, restart the kernel and run all cells from the top.

3. Why does the notebook need `ipykernel` in `.venv`, but not the full Jupyter package?
   - A. `ipykernel` is the new name for Jupyter, which it has fully replaced
   - B. VS Code provides the notebook interface; `.venv` only has to act as a kernel
   - C. The full Jupyter package doesn't install or run on Windows laptops
   - D. `ipykernel` bundles pandas and numpy, so the data libraries come with it

   Answer: B. VS Code's Jupyter extension provides the notebook interface. The environment only needs `ipykernel` so it can act as the kernel, the Python process that runs the cells with your course libraries.

4. Why read `Plant` and `Delivery` as text rather than numbers?
   - A. They are codes, not quantities; read as numbers, leading zeros vanish
   - B. Text columns make the model train faster than numeric columns do
   - C. pandas can't read numbers from a CSV unless they are marked as text
   - D. SAP requires text in every CSV column, or the file can't be read back

   Answer: A. They are SAP codes, not quantities. Read as numbers, leading zeros disappear and codes can be summed or sorted wrongly. Set `dtype` to `str` when reading the CSV.

5. Your check script says `OK` for every library, but a notebook cell fails with `No module named 'pandas'`. What is the likely cause?
   - A. pandas isn't installed anywhere on the laptop
   - B. The CSV file the notebook cell reads is missing
   - C. VS Code needs to be reinstalled from scratch
   - D. The notebook is using a different Python kernel

   Answer: D. The notebook uses a different Python. Click the kernel name at the top right and choose the one inside your course `.venv`.

6. How do the four data libraries depend on each other?
   - A. numpy is built on top of pandas, which holds the tables
   - B. They are independent and share no code with each other
   - C. pandas, scikit-learn and matplotlib all build on numpy
   - D. scikit-learn needs matplotlib to train and score its models

   Answer: C. numpy is the base for arithmetic on arrays. pandas builds tables on numpy, scikit-learn builds models on numpy and SciPy, and matplotlib draws charts from numpy data. `pip` installs the extra dependencies for you.

7. Why do the numbers from `hello_data.py` match the page?
   - A. It downloads the same sample data from an SAP system on each run
   - B. A fixed random seed makes the made-up data the same on every run
   - C. It reads a CSV file of deliveries that ships with the course
   - D. The model has memorized the page's numbers during training

   Answer: B. It makes 500 made-up, SAP-shaped deliveries, summarizes late deliveries by plant, draws a chart, and trains and scores a first model. A fixed random seed makes the data identical on every run; small version differences may change the last decimal.

8. When would you prefer SAP's hana-ml, which runs the model inside SAP HANA, over pandas and scikit-learn on a laptop?
   - A. For large SAP tables, or data that must not leave the system
   - B. For any small dataset under 1,000 rows that fits on a laptop
   - C. Whenever you work on a laptop and want results quickly
   - D. When you have no SAP HANA Cloud instance to connect to

   Answer: A. For large SAP tables and for data that must not leave the system, because the model runs in the database next to the data. It needs an SAP HANA Cloud instance with the right features enabled, and isn't needed for Unit 17.

## Sources

- [Jupyter Notebooks in VS Code (VS Code docs)](https://code.visualstudio.com/docs/datascience/jupyter-notebooks): Jupyter extension, Create New Jupyter Notebook command, kernel picker, run-cell shortcuts, Variables view, Data Viewer, saving plots
- [Manage Jupyter Kernels in VS Code (VS Code docs)](https://code.visualstudio.com/docs/datascience/jupyter-kernel-management): Select Kernel button, Python Environments option, only ipykernel is required in the environment
- [numpy (PyPI)](https://pypi.org/project/numpy/): pinned 2.4.6 supports Python 3.11; the 2.5 releases (2.5.5 latest on 2026-11-26) require Python 3.12 or newer
- [pandas (PyPI)](https://pypi.org/project/pandas/): pinned 3.0.6 (September 2026) requires Python 3.11 or newer; 3.1.1 was the latest on 2026-11-26
- [scikit-learn (PyPI)](https://pypi.org/project/scikit-learn/): latest release 1.9.1 (September 2026) requires Python 3.11 or newer; depends on NumPy and SciPy
- [matplotlib (PyPI)](https://pypi.org/project/matplotlib/): latest release 3.11.2 (September 2026) requires Python 3.11 or newer
- [ipykernel (PyPI)](https://pypi.org/project/ipykernel/): the IPython kernel for Jupyter; 7.4.0 released 2026-09-29, requires Python 3.11 or newer
- [hana-ml (PyPI)](https://pypi.org/project/hana-ml/): Python machine learning client for SAP HANA; HANA DataFrame, PAL and APL; converts to and from pandas; SAP Developer License; 2.30.26091800 released 2026-09-22
- [Developing AI workflows with the Python Machine Learning Client for SAP HANA (SAP Learning)](https://learning.sap.com/learning-journeys/developing-ai-workflows-with-the-python-machine-learning-client-for-sap-hana): SAP learning journey for hana-ml with PAL regression, classification and forecasting
- [Setting up the environment: regression models with hana-ml (SAP Learning)](https://learning.sap.com/courses/developing-regression-models-with-the-python-machine-learning-client-for-sap-hana/setting-up-the-environment): prerequisite of an SAP HANA Cloud instance with script server, PAL and APL enabled; written for hana-ml 2.21
- [venv: creation of virtual environments (Python docs)](https://docs.python.org/3/library/venv.html): Activate.ps1 path on Windows and the Set-ExecutionPolicy RemoteSigned command for the current user
- [Jupyter extension (Visual Studio Marketplace)](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter): extension ms-toolsai.jupyter published by Microsoft, free
