This is a textbook repository for the ETHZ Machine Learning for Mechanical Engineering course.
This guide provides step-by-step instructions to set up the machine learning environment required for this course. No prior Python experience is required.
Click the badge below (or the one at the top of this page). After a short wait a JupyterLab session opens in your browser with every package this book needs already installed.
- Click the badge. The first launch after a repository update can take several minutes while the environment builds. Later launches usually take under a minute.
- Open a notebook from the file browser on the left (start in the
part1/folder). - Run cells with
Shift+Enter.
Good to know:
- Your work is not saved on the server. A session shuts down after about 10 minutes of inactivity, and everything in it is discarded. To keep your changes, download the notebook (right-click the file β Download) before you leave. You can upload it again next time.
- Sessions are limited to roughly 1β2 GB of memory and have no GPU. That is plenty for Part 1 and most exercises. For the heavier generative-model notebooks in Part 2, use the local setup or Colab (below).
- If a launch fails with a capacity message, wait a minute and try again. Binder is a free, shared service.
The environment Binder builds is defined in binder/requirements.txt.
It is separate from the local setup below, so changing one does not affect the other.
For students who prefer a cloud-based environment without local installation:
- Go to colab.research.google.com
- Sign in with your Google account
- Click "New Notebook"
- Upload any
.ipynbfile from this book (from thenotebooksfolder) - Install the few packages Colab does not ship by running this in the first cell
(PyTorch, NumPy, pandas, scikit-learn and matplotlib are already installed on Colab):
!pip install --quiet pyro-ppl torchdiffeq geomloss gymnasium engibench
- Enable GPU (optional): Runtime β Change runtime type β GPU β Save
Benefits:
- No local installation required
- Free GPU access (CUDA automatically configured)
- Runs entirely in your browser
- Most packages pre-installed
Note: You will need to reinstall packages each time you start a new Colab session.
You need these 2 things:
-
Miniforge (Python package manager)
- Download from the official conda-forge website
- Choose the appropriate installer for your operating system
- Windows: Double-click the
.exefile and follow the installer - Mac/Linux: After downloading, run these commands in Terminal:
# For Mac (choose the right one for your chip): chmod +x Miniforge3-latest-MacOSX-arm64.sh # Apple Silicon (M1/M2/M3) # or chmod +x Miniforge3-latest-MacOSX-x86_64.sh # Intel Mac # or chmod +x Miniforge3-latest-Linux-x86_64.sh # Linux # Then run the appropriate installer: ./Miniforge3-latest-MacOSX-arm64.sh # Apple Silicon # or ./Miniforge3-latest-MacOSX-x86_64.sh # Intel Mac # or ./Miniforge3-latest-Linux-x86_64.sh # Linux
-
VS Code (code editor)
- Download from code.visualstudio.com
- Install it (just click through the installer)
Copy this book to your computer (choose one method):
Method A: VS Code Git Clone (Recommended)
- Open VS Code
- Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(Mac) - Type "Git: Clone" and press Enter
- Paste this URL:
https://github.com/IDEALLab/ML4ME_Textbook.git - Choose a folder (like Desktop or Documents)
- Wait for it to download
Method B: Direct Download (Easiest)
- Go to github.com/IDEALLab/ML4ME_Textbook
- Click "Code" β "Download ZIP"
- Extract the ZIP file to your desired folder
- Open the folder in VS Code
This installs everything automatically:
-
Open Terminal/Command Prompt:
- Windows: Open "Miniforge Prompt" from Start Menu (NOT regular Command Prompt!)
- Mac: Press
Cmd+Space, type "Terminal", press Enter - Linux: Press
Ctrl+Alt+T
-
Navigate to the book folder:
cd ML4ME_Textbook -
Run the setup script:
- Windows: Type
python bootstrap_env.pyin Miniforge Prompt - Mac/Linux: Type
python bootstrap_env.pyin terminal
- Windows: Type
-
Wait 5-10 minutes (the script downloads and installs required software)
-
Setup complete
You only need a GitHub account if you want to:
- Contribute to the course materials
- Create your own repositories
- Use advanced Git features
To create a free account:
- Go to github.com
- Click "Sign up"
- Create your account (use your ETH email if you have one)
- Verify your email
Note: This is completely optional for just using the course materials.
The setup script automatically:
- β
Created a Python environment called
ml4me-student - β Installed PyTorch (for deep learning) with proper CUDA support
- β Installed all ML libraries from the project dependencies (NumPy, Matplotlib, Pandas, Scikit-learn, Jupyter, etc.)
- β Set up everything needed to run the interactive notebooks
The complete textbook is available online at: https://ideal.umd.edu/ML4ME_Textbook/
VS Code provides an integrated development environment with excellent Jupyter support and is the recommended approach for this course.
- Open VS Code
- Open the book folder
- Click on any
.ipynbfile in thenotebooksfolder - VS Code will ask you to select a kernel - choose "ml4me-student"
- Start coding! The notebook will run directly in VS Code
Advantages of VS Code for ML development:
- Integrated experience - no switching between browser and terminal
- Smart autocomplete and IntelliSense for Python
- Built-in debugging tools for troubleshooting
- Git integration for version control
- Extension ecosystem for ML/AI development
- Integrated terminal for running commands
Every time you want to work on this book:
- Open VS Code
- Open the book folder (File β Open Folder)
- Click on any
.ipynbfile in thenotebooksfolder - Select "ml4me-student" kernel when prompted
- Start coding! Everything runs in VS Code
When you're done:
- Just close VS Code or the notebook file - that's it!
- Solution: Install Miniforge from conda-forge.org/download
- Restart your terminal after installing
- Solution: Make sure you have Python installed and accessible in your terminal
- Solution: Make sure you activated the environment:
conda activate ml4me-student
- Solution:
- Press
Ctrl+Shift+P(orCmd+Shift+Pon Mac) - Type "Python: Select Interpreter"
- Choose the one with
ml4me-student
- Press
- Solution:
- Open a
.ipynbfile in VS Code - Method 1: Click on the kernel name in the top-right corner of the notebook
- Method 2: Press
Ctrl+Shift+P(orCmd+Shift+Pon Mac), type "Notebook: Select Notebook Kernel" - Select "ml4me-student" from the list
- If not listed, select "Select Another Kernel" β "Python Environments" β "ml4me-student"
- Open a
- Solution: Always use "Miniforge Prompt" from Start Menu, NOT regular Command Prompt
- Solution: Use Method B (Direct Download) instead, or create a free GitHub account if you want to use Git features
- Solution: The first launch after the book is updated rebuilds the environment, which can take 5β15 minutes. Leave the tab open. If it fails outright, wait a minute and click the badge again.
- Solution: Binder sessions are temporary and end after ~10 minutes of inactivity. Download your notebook (right-click β Download) before leaving, and upload it into a new session to continue. For work you want to keep long-term, use the local setup.
- Solution: The session ran out of memory (about 2 GB). Reduce the dataset or model size, or run that notebook locally or on Colab.
- Solution: Run the package installation cell first:
!pip install --quiet pyro-ppl torchdiffeq geomloss gymnasium engibench
- Solution:
- Runtime β Restart runtime
- Or use CPU: Runtime β Change runtime type β CPU β Save
- Solution: This is normal - just reconnect and re-run the package installation cell
| What you want to do | Command |
|---|---|
| Activate environment | conda activate ml4me-student |
| Deactivate environment | conda deactivate |
| Check Python version | python --version |
| List installed packages | pip list |
| Update a package | pip install --upgrade package_name |
- Check this guide first - most common problems are covered here
- Ask your classmates - they may have encountered the same issue
- Contact your instructor for additional support
- "Module not found" β Make sure you selected the "ml4me-student" kernel in VS Code
- CUDA/NVIDIA messages when activating environment β This is normal on Windows/Linux with NVIDIA GPUs; macOS doesn't show these because CUDA packages aren't present there
I am using Quarto for this book, and you can render the book using the following steps:
- Install Quarto.
- Clone this repository.
- Preview the book via the command line (allows you to edit the book and see changes live):
quarto preview- Render the book via the command line (allows you to compile the book into HTML in
_book):
quarto render- If you want to render the book into PDF (will be placed in the
_bookfolder), you can use:
quarto render --to pdfYou now have a complete machine learning environment set up. You can:
- Read the interactive textbook
- Run all the example notebooks
- Complete the problem sets
- Start your own ML projects
This setup guide was created to make machine learning accessible to everyone, regardless of their programming background. If you have suggestions for improvements, please let us know!