MLI - MLII Exercise Setup
The Machine Learning 1 & Machine Learning 2 exercises require you to have a working Python environment. There are two options that you can pursue to reach that goal.
Setup
Option 1 (easiest): Google Colab - a web based Jupyter notebook.
- Sign in to your Google Account or create a new one
- Go to Colaboratory
- Create a new Python 3 notebook
Option 2: Installation on local machine
-
Install Python 3 from https://www.python.org/downloads/ and make sure to add Python to your PATH variable. At 16.10.2024 Python 3.11 is recommended as PyTorch won't work on later versions.
-
Open a command line and execute the following steps:
-
NOTE: You might need to replace the command
python3
in the following instructions withpy
if you are on Windows. -
Upgrade pip:
python3 -m pip install --upgrade pip
-
Create a folder dedicated to all virtual environments:
mkdir ~/envs
-
Switch to that folder:
cd ~/envs
-
Create a virtual environment:
python3 -m venv ml_env
-
Source this virtual environment:
-
Windows:
- If you use Powershell, make sure that local scripts can be run without signing. If this option is not activated yet, run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
- Run:
ml_env\Scripts\activate (or ml_env\Scripts\Activate.ps1 if you use Powershell)
- If you use Powershell, make sure that local scripts can be run without signing. If this option is not activated yet, run:
-
Linux, MacOS:
source ml_env/bin/activate
-
Windows:
-
Install Jupyter notebook:
pip install notebook
Tip: If you want a more sophisticated IDE, have a look at VSCode.
-
Install required packages:
pip install ipykernel matplotlib seaborn numpy pandas sklearn
-
Install PyTorch with
pip
by following these instructions here. If your computer has an NVIDIA GPU, choose an option with CUDA. If you are on Linux and use an AMD GPU you can try ROCM. Windows with AMD GPU or generally PCs without GPU should choose the option CPU. -
Install the activated environment as an IPython kernel:
python -m ipykernel install --user --name=ml_env
-
Switch to your working directory (i.e., where your notebooks are stored):
cd <YOUR_PATH>
-
Start a Jupyter notebook:
jupyter notebook
-
Go to http://localhost:8888
-
Click new in the upper right corner and select ml_env
-
Verification Step
To verify that everything has been set up correctly, run the following commands in your activated environment to confirm the installations:
# Check Python version
python --version
# Check pip version
pip --version
# Check installed packages
python -c "import numpy, pandas, sklearn, matplotlib, seaborn; print('Packages are installed successfully!')"
# Test Jupyter Notebook
jupyter notebook --version
If the commands execute without any errors and display the expected versions, your setup is complete and you are ready to start with the exercises!